spl_autoload_register记载顺序问题

解释一下为何会出现下列结果!?
我申报PHP BUG了!http://bugs.php.net/bug.php?id=54541
  1. A0Class.php
  2. <?

  3. namespace TESTING;


  4. use TESTING\BClass;

  5. class A0Class extend BClass{

  6. }


  7. A1Class.php

  8. <?

  9. namespace TESTING;

  10. use TESTING\BClass;

  11. class A1Class extend BClass{

  12. }


  13. BClass.php

  14. <?

  15. namespace TESTING;

  16. use TESTING\BClass;

  17. class BClass{

  18.      public function __construct(){

  19.          echo "Child Start";

  20.      }

  21. }


  22. Bootstrap.php

  23. <?php

  24. namespace TESTING;

  25. class Bootstrap {        

  26.         private static $classes = array ();
  27.         
  28.         public static function init() {

  29.                

  30.                 Bootstrap::requireOnce ( __DIR__ );

  31.                

  32.                 Bootstrap::loadClass ();

  33.         }

  34.         public static function getClasses() {

  35.                

  36.                 return Bootstrap::$classes;

  37.         }

  38.         private static function requireOnce($path) {

  39.                 foreach ( scandir ( $path ) as $object ) {

  40.                         if ($object != '.' && $object != '..') {

  41.                                 $object = $path . DIRECTORY_SEPARATOR . $object;

  42.                                 if (is_file ( $object ) && file_exists ( $object )) {

  43.                                         if (preg_match ( '/\.php$/', $object ) && ! preg_match ('/Bootstrap\.php$/', $object ) && ! preg_match ( '/testFile\.php$/', $object ) && !in_array()) {

  44.                                                 Bootstrap::$classes [] = $object;

  45.                                         }

  46.                                 } else if (is_dir ( $object )) {

  47.                                         Bootstrap::requireOnce ( $object );

  48.                                 

  49.                                 }

  50.                         }

  51.                 }

  52.         }

  53.         
  54.         private static function loadClass() {

  55.                 for($i = 0; $i < count ( Bootstrap::$classes ); $i ++) {

  56.                         require_once Bootstrap::$classes [$i];

  57.                 }

  58.         }

  59. }


  60. spl_autoload_register ( array ('TESTING\Bootstrap', 'init' ) );


  61. testFile.php

  62. <?php

  63. require_once 'lib/Bootstrap.php';

  64. use TESTING\A0Class;

  65. $a0 = new A0Class();


  66. Expected result:
  67. ----------------
  68. Child Start

  69. Actual result:
  70. --------------
  71. Fatal error: Class 'TESTING\BClass' not found
复制代码

作者: soman0324   发布时间: 2011-06-15

回复 soman0324


    恩恩

作者: thin_life   发布时间: 2011-06-15

恩恩

作者: thin_life   发布时间: 2011-06-15