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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:43:401027Durchsuche


回复讨论(解决方案)

两个都可以注册成功,你的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);

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn