Home > Backend Development > PHP Tutorial > 我的spl_auto_register()函数为什么只能注册一个自动加载函数呢?

我的spl_auto_register()函数为什么只能注册一个自动加载函数呢?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:43:40
Original
1025 people have browsed it


回复讨论(解决方案)

两个都可以注册成功,你的autoload函数require之前 先要判断是否是文件啊,亲

function __autoload1($className) {        $path = 'class/' . $className . ".class.php";    if (is_file($path))        require_once 'class/' . $className . ".class.php";}function __autoload2($phpFile) {    $path = $phpFile . ".class.php";    echo $path;    if (is_file($path))        require_once $phpFile . ".class.php";}spl_autoload_register('__autoload1');spl_autoload_register('__autoload2');$page = new Page;$person = new Person();print_r($page);print_r($person);
Copy after login

哦。谢谢,原来是要判断再载入,而不是让他载入失败,再去找第二个函数。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template