From:             michaelduff2 at yahoo dot com
Operating system: RedHat
PHP version:      5.4.5
Package:          SPL related
Bug Type:         Bug
Bug description:Using derived autoloader classes doesn't work

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 bug report at https://bugs.php.net/bug.php?id=62808&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=62808&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=62808&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=62808&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=62808&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=62808&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=62808&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=62808&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=62808&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=62808&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=62808&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=62808&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=62808&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=62808&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=62808&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=62808&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=62808&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=62808&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=62808&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=62808&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=62808&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=62808&r=mysqlcfg

Reply via email to