Edit report at https://bugs.php.net/bug.php?id=65999&edit=1
ID: 65999
Comment by: gg at ez dot no
Reported by: giunta dot gaetano at gmail dot com
Summary: autoloading of aliased namespaced classes fails when
including twice a file
Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: win7 64bit
PHP Version: 5.4.21
Block user comment: N
Private report: N
New Comment:
OK - but then maybe this could be made more clear in the docs?
Previous Comments:
------------------------------------------------------------------------
[2013-10-31 16:11:11] [email protected]
String class names must always be fully qualified, i.e. if you need to write
class_exists('A\B\C'). Namespace aliases don't work in strings.
If you are using PHP 5.5 you can alternatively write class_exists(A::class).
------------------------------------------------------------------------
[2013-10-30 16:45:05] gg at ez dot no
...and apparently it has nothing to do with re-including the original file (my
bad)
------------------------------------------------------------------------
[2013-10-30 16:42:50] gg at ez dot no
Here's a test file with a somewhat odd result:
<?php
use A\B\C as A;
if (!isset($alreadyIncluded)) {
spl_autoload_register('var_dump');
$alreadyIncluded = true;
include __FILE__;
} else {
class_exists( 'A' ); // 'A'
new A; // 'A\B\C'
}
------------------------------------------------------------------------
[2013-10-30 16:37:15] giunta dot gaetano at gmail dot com
You are correct, the provided test file has no problems.
The error I have is with a slightly more complex setup - a composer-generated
autoloader class.
I will try to reproduce the error with a minimal setup...
------------------------------------------------------------------------
[2013-10-30 14:48:28] [email protected]
Could you please provide a short reproduce script for your issue? I tried the
following code, which autoloaded 'A\B\C', not 'D':
<?php
use A\B\C as D;
if (!isset($alreadyIncluded)) {
spl_autoload_register('var_dump');
$alreadyIncluded = true;
include __FILE__;
} else {
new D;
}
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=65999
--
Edit this bug report at https://bugs.php.net/bug.php?id=65999&edit=1