|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-08-03 16:19 UTC] david at grudl dot com
Description:
------------
is_callable() and method_exists() may invoke autoloader with unnecessary namespace backslash.
\My\MyClass::func() is the same as My\MyClass::func().
Reproduce code:
---------------
function __autoload($name)
{
echo $name;
}
is_callable('\My\MyClass::func'); // ERROR
is_callable('My\MyClass::func'); // OK
method_exists('\My\MyClass', 'func'); // ERROR
method_exists('My\MyClass', 'func'); // OK
// defined works well:
defined('\My\MyClass::CONST'); // OK
defined('My\MyClass::CONST'); // OK
Expected result:
----------------
My\MyClass
My\MyClass
My\MyClass
My\MyClass
My\MyClass
My\MyClass
Actual result:
--------------
\My\MyClass
My\MyClass
\My\MyClass
My\MyClass
My\MyClass
My\MyClass
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 18:00:01 2025 UTC |
This bug is still present in 5.3.2 and also affects instantiating a new class from a string variable: function __autoload($class) { echo "$class\n"; } $obj = new MyProject\Thing(); // correct: MyProject\Thing $obj = new \MyProject\Thing(); // correct: MyProject\Thing $class = '\\MyProject\\Thing'; $obj = new $class(); // wrong: \MyProject\Thing