|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-10-30 10:49 UTC] giunta dot gaetano at gmail dot com
Description: ------------ Imagine the following situation: - file X.php has a USE statement aliasing a class name A\B\C as D - it includes other files, which set up autoloading, then require X.php again - when X.php is reincluded, it executes some code, using an object: $x = new D() In this case, the functions registered for class autoloading will get passed the string 'D' instead of 'A\B\C' PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 17:00:01 2025 UTC |
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; }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' }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).