Edit report at https://bugs.php.net/bug.php?id=65999&edit=1
ID: 65999 Updated by: ni...@php.net Reported by: giunta dot gaetano at gmail dot com Summary: autoloading of aliased namespaced classes fails when including twice a file -Status: Open +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: 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). Previous Comments: ------------------------------------------------------------------------ [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] ni...@php.net 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; } ------------------------------------------------------------------------ [2013-10-30 10:50:08] giunta dot gaetano at gmail dot com [edited bug name] ------------------------------------------------------------------------ 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