|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50731 Inconsistent namespaces sent to functions registered with spl_autoload_register
Submitted: 2010-01-12 18:09 UTC Modified: 2010-03-03 01:16 UTC
Avg. Score:4.4 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:2 (50.0%)
From: court at epixa dot com Assigned: felipe (profile)
Status: Closed Package: SPL related
PHP Version: 5.3, 6 OS: *
Private report: No CVE-ID: None
 [2010-01-12 18:09 UTC] court at epixa dot com
When you instantiate a namespaced class, the expected behavior is for the fully qualified namespace with leading slash absent to be passed to your registered function.  However, if you instantiate a namespaced class with a class name stored in a variable, the fully qualified namespace is not evaluated and the leading slash (if specified) is included.

You'll have to run the reproduce code twice to see what I mean.

Reproduce code:
function loadClass($class) {
    die($class . PHP_EOL);


$myClass = '\Fully\Qualified\ClassName';

// run this first:
new \Fully\Qualified\ClassName();

// run this second:
//new $myClass();

Expected result:
First run:

Second run:

Actual result:
First run:

Second run:


Habbo (last revision 2015-05-22 17:13 UTC by gabrielbebe28 at outlook dot com dot br)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-12 22:52 UTC] court at epixa dot com
I don't know how I didn't notice this earlier, but it seems the issue isn't simply with a leading slash but with evaluating namespaces entirely for autoloading.  Consider the following code coupled with my original autoloader function:

namespace Fully\Qualified;
new ClassName();
// expects: Fully\Qualified\ClassName
// outputs: Fully\Qualified\ClassName

$myClass = 'ClassName';
new $myClass();
// expects: Fully\Qualified\ClassName
// outputs: ClassName

It is my understanding that the loader functions are executed in the global namespace and thus should only be dealing with fully qualified namespaces.  It appears as if the fully qualified namespace is evaluated and passed to registered autoloaders if the class name is specified explicitly, but the same cannot be said for class names that are created dynamically.
 [2010-02-19 08:31 UTC]
-Operating System: MAC OS X 10.6.2
+Operating System: *
-PHP Version: 5.3.1
+PHP Version: 5.3, 6

See also bug #51087
 [2010-03-03 01:15 UTC]
Automatic comment from SVN on behalf of felipe
Log: - Fixed bug #50731 (Inconsistent namespaces sent to functions registered with spl_autoload_register)
 [2010-03-03 01:16 UTC]
-Status: Open +Status: Closed
 [2010-03-03 01:16 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 05:01:31 2024 UTC