Bug #62808 [Fbk->NoF]: Using derived autoloader classes doesn't work

From: Date: Sun, 03 Jul 2016 04:22:20 +0000
Subject: Bug #62808 [Fbk->NoF]: Using derived autoloader classes doesn't work
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201997@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 Updated by: php-bugs@lists.php.net Reported by: michaelduff2 at yahoo dot com Summary: Using derived autoloader classes doesn't work -Status: Feedback +Status: No Feedback Type: Bug Package: SPL related Operating System: RedHat PHP Version: 5.4.5 Assigned To: cmb Private report: N New Comment: No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Re-Opened". Thank you. Previous Comments: ------------------------------------------------------------------------ [2016-06-20 14:43:06] cmb@php.net Yes, please provide a self-contained test script. Note that it's probably not necessary to include the actual loading code; echo'ing the relevant variables should be sufficient. ------------------------------------------------------------------------ [2015-04-24 05:13:21] michaelduff2 at yahoo dot com 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? ------------------------------------------------------------------------ [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 (#201997) next »