Bug #65999 [Com]: autoloading of aliased namespaced classes fails when including twice a file

From: Date: Thu, 31 Oct 2013 16:40:51 +0000
Subject: Bug #65999 [Com]: autoloading of aliased namespaced classes fails when including twice a file
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182526@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65999&edit=1 ID: 65999 Comment by: nikic@php.net 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: The behavior of namespaces with "dynamic" features in documented in http://php.net/manual/en/language.namespaces.dynamic.php Previous Comments: ------------------------------------------------------------------------ [2013-10-31 16:14:42] gg at ez dot no OK - but then maybe this could be made more clear in the docs? ------------------------------------------------------------------------ [2013-10-31 16:11:11] nikic@php.net 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... ------------------------------------------------------------------------ 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

« previous php.bugs (#182526) next »