Last active
April 13, 2019 06:26
-
-
Save cebe/6206940 to your computer and use it in GitHub Desktop.
PHP autoload function return values do not make any sense!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php class A {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
spl_autoload_register(function($class) { | |
echo "autoloader 1\n"; | |
if ($class == 'A') | |
include 'A.php'; | |
if ($class == 'C') | |
return true; | |
if ($class == 'D') | |
return false; | |
}); | |
spl_autoload_register(function($class) { | |
echo "autoloader 2\n"; | |
if ($class == 'B') | |
include 'B.php'; | |
return true; | |
}); | |
spl_autoload_register(function($class) { | |
echo "autoloader 3\n"; | |
}); | |
echo "instantiate A...\n"; | |
$a = new A(); | |
echo "instantiate B...\n"; | |
$b = new B(); | |
echo "instantiate C...\n"; | |
if (class_exists('C')) | |
echo "C exists\n"; | |
echo "instantiate D...\n"; | |
if (class_exists('D')) | |
echo "D exists\n"; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php class B {} |
PHP source says the same: https://github.com/php/php-src/blob/1d6a136051051e4e25f89a280ca92fde2da04463/ext/spl/php_spl.c#L411
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: