|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-02-19 08:31 UTC] jani@php.net
[2010-02-19 17:41 UTC] andrey at ning dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 08 04:00:01 2025 UTC |
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