Bug #62808 [Com]: Using derived autoloader classes doesn't work

From: Date: Fri, 24 Apr 2015 05:13:21 +0000
Subject: Bug #62808 [Com]: Using derived autoloader classes doesn't work
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192313@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62808&edit=1 ID: 62808 Comment by: michaelduff2 at yahoo dot com Reported by: michaelduff2 at yahoo dot com Summary: Using derived autoloader classes doesn't work Status: Open Type: Bug Package: SPL related Operating System: RedHat PHP Version: 5.4.5 Block user comment: N Private report: N New Comment: Any work on this? Re-reading the test case presented, I see that it is incomplete and slightly misleading (I don't believe \DerivedLibrary\SomeClass needs to extend \BaseLibrary\SomeClass to exhibit the problem), and I also see that no erroneous implementation is provided, nor are the expected vs. actual results. ...So. I am going to whip up a real test case myself, give it a try on the most recent PHP I have at the moment, and report back here with the results and an executable script. --Unless someone knows this has been fixed already? Previous Comments: ------------------------------------------------------------------------ [2012-08-13 09:23:09] michaelduff2 at yahoo dot com Description: ------------ This case breaks autoloading, because of an apparent assumption in the way spl_autoload processes its registered functions: namespace BaseLibrary { class Loader { protected static $ns=__NAMESPACE__; protected static $dir=__DIR__; function Load($class_name) { // ...fully tested code for autoloading classes // using static::$ns and static:$dir... } } class SomeClass { } } namespace DerivedLibrary { class Loader extends \BaseLibrary\Loader { protected static $ns=__NAMESPACE__; protected static $dir=__DIR__; } class SomeClass extends \BaseLibrary\SomeClass { } } When an attempt is made to load \DerivedLibrary\SomeClass, spl_autoload finds it correctly, include()s the file, but then never calls \BaseLibrary\Loader::Load('\BaseLibrary\SomeClass') -- which is necessary because \DerivedLibrary\SomeClass extends \BaseLibrary\SomeClass and \DerivedLibrary\Loader extends \BaseLibrary\Loader. It simply throws "Class does not exist." My guess is that the spl_autoload queue uses globally scoped data rather than function-scoped (stack) data to manage its traversal of the autoload functions, OR because spl_autoload peeks at the function call stack to ascertain which autoloaders it has already called (probably to avoid loops). If \DerivedLibrary\Loader is made into a verbatim copy of \BaseLibrary\Loader (i.e., copying the file and changing only the namespace declaration -- thereby implicitly removing the 'extends \BaseLibrary\Loader') ... then immediately everything works! ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62808&edit=1

« previous php.bugs (#192313) next »