From:             
Operating system: Ubuntu 10.04
PHP version:      5.3.3
Package:          SPL related
Bug Type:         Feature/Change Request
Bug description:Autoload should not cancel if called for same class twice

Description:
------------
hi,



currently i am using a require-all-script in my system that just plain
require-once's all files with correct ending (".class.php";".mdl.php";...)
it can find.

This happens inside of an autoload-method,

calling itself again when a depency (e.g. inheritance) occours.

when called again, it will skip all already called includes, since they are
require-_once_. Whith this loader i can just add a class file and it will
be loaded automaticly without needing me to register it somewhere
manually.



But it seems i have misunderstood the documentation,

because i now have noticed that when two classes extends the same class,

it will fail at the second child-class complaining that the parent-class is
missing instead of just calling autoload again for the same class,

which i thought will happen.



now i have to build the initial-loader much more complex, holding a cached
depency-list of classes or looking into the source-code when called.

Test script:
---------------
<?php



function __autoload($class){



        // throws "Class C not found"

        //   i think it would be cool if it would call autoload again to load C,

        //   so this require_once wont be called again, class C would be loaded
and everything would be fine.

        require_once("B.class.php"); // <-- "<?php class B extends C{}"



        // this will never be called

        require_once("C.class.php"); // <-- "<?php class C{}"

}



// this will call autoload to load class "C"

require_once("A.class.php"); // <-- "<?php class A extends C{}"



echo "this will never be echo'd...";



?>

Expected result:
----------------
<?php // EXPECTED:



function __autoload($class){



        // calls autoload again, will be skipped in that second call

        require_once("B.class.php"); // <-- "<?php class B extends C{}"



        // will be included in second call, then skippen when back in first run

        require_once("C.class.php"); // <-- "<?php class C{}"

}



// this will call autoload to load class "C"

require_once("A.class.php"); // <-- "<?php class A extends C{}"



// C, B and A are loaded correctly



?>

Actual result:
--------------
<?php // ACTUAL:



function __autoload($class){



        // throws fatal error "Class C not found"

        require_once("B.class.php"); // <-- "<?php class B extends C{}"



        // this will never be called

        require_once("C.class.php"); // <-- "<?php class C{}"

}



// this will call autoload to load class "C"

require_once("A.class.php"); // <-- "<?php class A extends C{}"



// none class clould be loaded, since it Fatal-error's at B.



?>

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

Reply via email to