ID:               51087
 User updated by:  andrey at ning dot com
 Reported By:      andrey at ning dot com
 Status:           Bogus
 Bug Type:         SPL related
 Operating System: any
 PHP Version:      5.3.2RC2
 New Comment:

The issue I'm describing is similar, but different it terms of how
spl_autoload handles the cases I'm describing. 
spl_autoload should NOT try going further in the list of autoload
handlers when the class is already loaded, but the bug is it considers
classes "foo\bar" and "\foo\bar" different and loading "foo\bar" doesn't
make "\foo\bar" to appear as loaded.


Previous Comments:
------------------------------------------------------------------------

[2010-02-19 08:31:29] [email protected]

-Status: Open
+Status: Bogus

Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

See bug #50731

------------------------------------------------------------------------

[2010-02-19 01:17:35] andrey at ning dot com

Description:
------------
When several autoload handlers are registered with
spl_autoload_register, and the class starting with T_NS_SEPARATOR (\)
AND created using the variable class name is autoloaded, spl_autoload
does not stop at the first successful item and goes thru the whole
stack.


Reproduce code:
---------------
// Source files:
// foo-bar1.php
namespace foo; class bar1 {}

// foo-bar2.php
namespace foo; class bar2 {}

// foo-baz1.php
namespace foo; class baz1 {}

// foo-baz2.php
namespace foo; class baz2 {}

// test.php
function autoload1($class) {
    echo "autoload1($class) is called!\n";
    $path = array_filter(explode('\\', $class), 'strlen');
    require join('-', $path) . ".php";
}
function autoload2($class) {
    echo "autoload2($class) is called!\n";
    $path = array_filter(explode('\\', $class), 'strlen');
    require join('-', $path) . ".php";
}
spl_autoload_register('autoload1');
spl_autoload_register('autoload2');

$f = new foo\bar1;
$f = new \foo\baz1;
$class = "foo\\bar2"; $f = new $class;
$class = "\\foo\\baz2"; $f = new $class;


Expected result:
----------------
autoload1(foo\bar1) is called!
autoload1(foo\baz1) is called!
autoload1(foo\bar2) is called!
autoload1(\foo\baz2) is called!


Actual result:
--------------
autoload1(foo\bar1) is called!
autoload1(foo\baz1) is called!
autoload1(foo\bar2) is called!
autoload1(\foo\baz2) is called!
autoload2(\foo\baz2) is called!
PHP Fatal error:  Cannot redeclare class foo\baz2



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=51087&edit=1

Reply via email to