Doc #67936 [NEW]: The spl_autoload_register() function uses queue but not stack
| From: | alegil91 at gmail dot com | Date: | Sat, 30 Aug 2014 06:49:17 +0000 |
| Subject: | Doc #67936 [NEW]: The spl_autoload_register() function uses queue but not stack | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-11456@lists.php.net to get a copy of this message | ||
From: alegil91 at gmail dot com
Operating system: Doesn't matter
PHP version: Irrelevant
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:The spl_autoload_register() function uses queue but not stack
Description:
------------
---
From manual page: http://www.php.net/function.spl-autoload-register
---
Why do you call the "stack" what spl_autoload_register function uses? I
was really really embarassed when I was debugging my script. Correct me
if I'm wrong but the stack is a data structure that uses LIFO mechanism
to store its entities. That means that what you added last is gonna to
be pulled out of the stack first (Last In - First out).
And what php uses is just a list, that can be appended or prepended
depending on what your arguments are. By default, the $prepend argument
is false. I suppose it's more a queue rather than stack.
Test script:
---------------
<?php
function register_other1() {
echo "\nreg1";
spl_autoload_register(function ($className) {
echo "\nCan not load class with other autoload 1: " .
$className;
});
}
register_other1();
function register_other2() {
echo "\nreg2";
spl_autoload_register(function ($className) {
echo "\nCan not load class with other autoload 2: " .
$className;
});
}
register_other2();
function register_other3() {
echo "\nreg3";
spl_autoload_register(function ($className) {
echo "\nCan not load class with other autoload 3: " .
$className;
});
}
register_other3();
var_dump(spl_autoload_functions());
new \Sasa\Lol\Prol();
Expected result:
----------------
reg1
reg2
reg3
Can not load class with other autoload 3: Sasa\Lol\Prol
Can not load class with other autoload 2: Sasa\Lol\Prol
Can not load class with other autoload 1: Sasa\Lol\Prol
Actual result:
--------------
reg1
reg2
reg3
array (size=3)
0 =>
object(Closure)[1]
1 =>
object(Closure)[2]
2 =>
object(Closure)[3]
Can not load class with other autoload 1: Sasa\Lol\Prol
Can not load class with other autoload 2: Sasa\Lol\Prol
Can not load class with other autoload 3: Sasa\Lol\Prol
--
Edit bug report at https://bugs.php.net/bug.php?id=67936&edit=1
--