#51087 [NEW]: spl_autoload doesn't handle classes starting with T_NS_SEPARATOR properly

From: Date: Fri, 19 Feb 2010 01:17:35 +0000
Subject: #51087 [NEW]: spl_autoload doesn't handle classes starting with T_NS_SEPARATOR properly
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-147841@lists.php.net to get a copy of this message
From: andrey at ning dot com Operating system: any PHP version: 5.3.2RC2 PHP Bug Type: SPL related Bug description: spl_autoload doesn't handle classes starting with T_NS_SEPARATOR properly 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 bug report at http://bugs.php.net/?id=51087&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51087&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51087&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51087&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51087&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51087&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51087&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51087&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51087&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51087&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51087&r=support Expected behavior: http://bugs.php.net/fix.php?id=51087&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51087&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51087&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51087&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51087&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51087&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51087&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51087&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51087&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51087&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51087&r=mysqlcfg

« previous php.bugs (#147841) next »