spl_autoload_register记载顺序问题
解释一下为何会出现下列结果!?
我申报PHP BUG了!http://bugs.php.net/bug.php?id=54541
复制代码
我申报PHP BUG了!http://bugs.php.net/bug.php?id=54541
- 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
作者: soman0324 发布时间: 2011-06-15
回复 soman0324
恩恩
恩恩
作者: thin_life 发布时间: 2011-06-15
恩恩
作者: thin_life 发布时间: 2011-06-15