Bug #54541 [NEW]: spl_autoload_register Loading order
| From: | gys0324 at yeah dot net | Date: | Fri, 15 Apr 2011 13:03:03 +0000 |
| Subject: | Bug #54541 [NEW]: spl_autoload_register Loading order | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-160188@lists.php.net to get a copy of this message | ||
From:
Operating system: Win
PHP version: 5.2.17
Package: SPL related
Bug Type: Bug
Bug description:spl_autoload_register Loading order
Description:
------------
spl_autoload_register
Loading order
Test script:
---------------
A0Class.php
<?
namespace TESTING;
use TESTING\BClass;
class A0Class extend BClass{
}
A1Class.php
<?
namespace TESTING;
use TESTING\BClass;
class A1Class extend BClass{
}
BClass.php
<?
namespace TESTING;
use TESTING\BClass;
class BClass{
public function __construct(){
echo "Child Start";
}
}
Bootstrap.php
<?php
namespace TESTING;
class Bootstrap {
private static $classes = array ();
public static function init() {
Bootstrap::requireOnce ( __DIR__ );
Bootstrap::loadClass ();
}
public static function getClasses() {
return Bootstrap::$classes;
}
private static function requireOnce($path) {
foreach ( scandir ( $path ) as $object ) {
if ($object != '.' && $object != '..') {
$object = $path . DIRECTORY_SEPARATOR . $object;
if (is_file ( $object ) && file_exists ( $object )) {
if (preg_match ( '/\.php$/', $object ) && ! preg_match (
'/Bootstrap\.php$/', $object ) &&
! preg_match ( '/testFile\.php$/', $object )
&& !in_array()) {
Bootstrap::$classes [] = $object;
}
} else if (is_dir ( $object )) {
Bootstrap::requireOnce ( $object );
}
}
}
}
private static function loadClass() {
for($i = 0; $i < count ( Bootstrap::$classes ); $i ++) {
require_once Bootstrap::$classes [$i];
}
}
}
spl_autoload_register ( array ('TESTING\Bootstrap', 'init' ) );
testFile.php
<?php
require_once 'lib/Bootstrap.php';
use TESTING\A0Class;
$a0 = new A0Class();
Expected result:
----------------
Child Start
Actual result:
--------------
Fatal error: Class 'TESTING\BClass' not found
--
Edit bug report at http://bugs.php.net/bug.php?id=54541&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54541&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54541&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54541&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=54541&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54541&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=54541&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=54541&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=54541&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=54541&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=54541&r=support
Expected behavior: http://bugs.php.net/fix.php?id=54541&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=54541&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=54541&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=54541&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54541&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=54541&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=54541&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=54541&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=54541&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=54541&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=54541&r=mysqlcfg