ID: 49618 Updated by: sjo...@php.net Reported By: jost dot boekemeier at googlemail dot com Status: Bogus Bug Type: SPL related Operating System: Any PHP Version: 5.2.11 New Comment:
If two or more of the libraries use __autoload, it won't work, and there is nothing anybody can do about it. If all of the libraries use spl_autoload_register, it works as it should. If one of the libraries uses __autoload and others use spl_autoload_register, it is the task of the library that uses spl_autoload_register to register __autoload as well, like this: if (function_exists("__autoload")) spl_autoload_register("__autoload"); Previous Comments: ------------------------------------------------------------------------ [2009-09-22 09:26:02] jost dot boekemeier at googlemail dot com My code doesn't use __autoload. My code uses spl_autoloload. I have received a bug report because my code has destroyed an existing library. By issuing this bug report I have asked you to stop this, by either: * deprecating __autoload altogether * fix spl_autoload to honor an existing __autoload or * let library authors check for an existing (or upcoming) __autoload so that their library doesn't destroy existing code With the current behaviour I have no other choice but to not use spl_autoload at all, since I don't know whether the user will or will not include a library which uses __autoload later on. ------------------------------------------------------------------------ [2009-09-22 09:11:12] sjo...@php.net Thank you for your report. I do not think the behavior you describe is a bug. The documentation is clear about this: "If your code has an existing __autoload function then this function must be explicitly registered on the __autoload stack. This is because spl_autoload_register() will effectively replace the engine cache for the __autoload function by either spl_autoload() or spl_autoload_call()." Thus, calling spl_autoload_register() replaces __autoload(). ------------------------------------------------------------------------ [2009-09-22 05:24:02] jost dot boekemeier at googlemail dot com Description: ------------ The first call to spl_autoload_register destroys an existing __autoload hook. Please either deprecate __autoload and/or register __autoload with spl_autoload. Complete problem description is here: http://sourceforge.net/mailarchive/forum.php? thread_name=3afa16cf0909210312v3e102491n18701bcca0f5e030%40mail.gmail.com &forum_name=php-java-bridge-users Reproduce code: --------------- <?php function autoload_legacy($x) {echo "legacy "; return false;} function autoload_spl1($x) {echo "spl1 "; return false;} function autoload_spl2($x) {echo "spl2 "; return false;} function autoload_spl3($x) {echo "spl3 "; return false;} spl_autoload_register("autoload_spl1"); function __autoload($x) {return autoload_legacy($x);} spl_autoload_register("autoload_spl2"); spl_autoload_register("autoload_spl3"); @new Foo(); ?> Expected result: ---------------- spl1 spl2 spl3 legacy Actual result: -------------- spl1 spl2 spl3 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49618&edit=1