|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-06-09 16:14 UTC] nikic@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: nikic
[2020-06-09 16:14 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 06:00:02 2025 UTC |
Description: ------------ When spl_autoload_register() is called from within another auto load operation, spl_autoload_functions() will list the newly registered loader until PHP is done executing the newly included file, after which the loader is removed from the loader functions. Test script: --------------- <?php //generate auto loaded file first $base = ucfirst(basename(__FILE__, '.php')); $s = <<<EOM <?php $base::setup(); class $base { public static function setup() { spl_autoload_register(array(__CLASS__, 'load')); print_r(spl_autoload_functions()); } public static function load($class) { print_r(func_get_args()); } } EOM; file_put_contents(pathinfo(__FILE__, PATHINFO_FILENAME) . '.test.php', $s); spl_autoload_extensions('.test.php'); spl_autoload_register(); new $base; echo "after first autoload\n"; print_r(spl_autoload_functions()); echo "---\n"; new NonExistingClass; Expected result: ---------------- after spl_autoload_register() Array ( [0] => spl_autoload [1] => Array ( [0] => Loader [1] => load ) ) after first autoload Array ( [0] => spl_autoload [1] => Array ( [0] => Loader [1] => load ) ) --- Array ( [0] => NonExistingClass ) Fatal error: Class 'NonExistingClass' not found in loader.php on line 35 Actual result: -------------- after spl_autoload_register() Array ( [0] => spl_autoload [1] => Array ( [0] => Loader [1] => load ) ) after first autoload Array ( [0] => spl_autoload ) --- Fatal error: spl_autoload(): Class NonExistingClass could not be loaded in loader.php on line 35