Bug #50731 [Opn->Csd]: Inconsistent namespaces sent to functions registered with spl_autoload_register
| From: | felipe@php.net | Date: | Wed, 03 Mar 2010 00:16:09 +0000 |
| Subject: | Bug #50731 [Opn->Csd]: Inconsistent namespaces sent to functions registered with spl_autoload_register | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-148187@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=50731&edit=1
ID: 50731
Updated by: felipe@php.net
Reported by: court at epixa dot com
Summary: Inconsistent namespaces sent to functions registered
with spl_autoload_register
-Status: Open
+Status: Closed
Type: Bug
Package: SPL related
Operating System: *
PHP Version: 5.3, 6
Assigned To: felipe
New Comment:
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
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2010-03-03 01:16:09] felipe@php.net
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
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
------------------------------------------------------------------------
[2010-03-03 01:15:36] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&revision=295763
Log: - Fixed bug #50731 (Inconsistent namespaces sent to functions
registered with spl_autoload_register)
------------------------------------------------------------------------
[2010-02-19 08:31:57] jani@php.net
-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-01-12 22:52:03] 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-01-12 18:09:45] court at epixa dot com
Description:
------------
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);
}
spl_autoload_register('loadClass');
$myClass = '\Fully\Qualified\ClassName';
// run this first:
new \Fully\Qualified\ClassName();
// run this second:
//new $myClass();
Expected result:
----------------
First run:
Fully\Qualified\ClassName
Second run:
Fully\Qualified\ClassName
Actual result:
--------------
First run:
Fully\Qualified\ClassName
Second run:
\Fully\Qualified\ClassName
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=50731&edit=1