Bug #54541 [Opn->Nab]: spl_autoload_register Loading order
| From: | cmb@php.net | Date: | Sun, 08 Jul 2018 15:08:59 +0000 |
| Subject: | Bug #54541 [Opn->Nab]: spl_autoload_register Loading order | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-216227@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=54541&edit=1
ID: 54541
Updated by: cmb@php.net
Reported by: gys0324 at yeah dot net
Summary: spl_autoload_register Loading order
-Status: Open
+Status: Not a bug
Type: Bug
Package: SPL related
Operating System: Win
PHP Version: 5.3.6
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Your autoloader is severly broken. The issue you're facing is
similar to the following:
a.php
<?php
class A extends B {}
?>
b.php
<?php
class B {}
?>
test.php
<?php
require_once './a.php';
require_once './b.php';
?>
Previous Comments:
------------------------------------------------------------------------
[2011-04-17 05:26:24] gys0324 at yeah dot net
the problem is always found by the latest version
------------------------------------------------------------------------
[2011-04-15 15:44:15] gys0324 at yeah dot net
There is two classes extend BClass,
so the error has been happened.
But if just one class which is A0 or A1 extends BClass,
the expected result will be displayed.
------------------------------------------------------------------------
[2011-04-15 15:03:02] gys0324 at yeah dot net
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 this bug report at https://bugs.php.net/bug.php?id=54541&edit=1