Bug #49143 [Com]: is_callable() and unnecessary backslash
Edit report at http://bugs.php.net/bug.php?id=49143&edit=1
ID: 49143
Comment by: abca_b_cabcom at hotmail dot com
Reported by: david at grudl dot com
Summary: is_callable() and unnecessary backslash
Status: Open
Type: Bug
Package: Class/Object related
Operating System: *
PHP Version: 5.3.0
New Comment:
hi david, you are not in a namespace it is just a classname.
Previous Comments:
------------------------------------------------------------------------
[2009-08-04 11:24:35] david at grudl dot com
The two same class invokes autoloader with different class name (maybe
better term is non-canonicalized class name).
This means: every autoloader must call $name = ltrim($name, "\").
defined() removes leading "\" automatically, is_callable and
method_exists do not.
------------------------------------------------------------------------
[2009-08-04 11:16:07] jani@php.net
Yes, which problem..? I don't see any errors.
------------------------------------------------------------------------
[2009-08-04 00:34:46] david at grudl dot com
Tested with 5.3.1-dev (Sun, 02 Aug 2009 18:53:57 +0000), problem still
exists.
------------------------------------------------------------------------
[2009-08-03 16:19:59] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=49143&edit=1
Thread (8 messages)