Bug #51527 [Opn]: is_callable() returning true for non-static callbacks
| From: | pajoye@php.net | Date: | Sat, 10 Apr 2010 14:29:13 +0000 |
| Subject: | Bug #51527 [Opn]: is_callable() returning true for non-static callbacks | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-149471@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=51527&edit=1
ID: 51527
Updated by: pajoye@php.net
Reported by: weierophinney@php.net
Summary: is_callable() returning true for non-static callbacks
Status: Open
Type: Bug
Package: Class/Object related
Operating System: Linux
PHP Version: 5.3.2
New Comment:
It is actually callable. But calling it statically breaks the strict
standards, but the strict standards will break BC in many situations.
I would suggest to make this change in trunk only.
Previous Comments:
------------------------------------------------------------------------
[2010-04-10 16:07:17] weierophinney@php.net
Description:
------------
is_callable() is returning a false-positive for callbacks that reference
non-
static methods. As an example, if I have defined a class 'Foo' with an
instance
(i.e., non-static) method 'bar', and define the callback "array('Foo',
'bar')",
is_callable() will falsely return true.
Additionally, if you then pass this callback to call_user_func(), this
latter
function will actually try to call the method statically -- and raise an
E_STRICT about the callback being invalid. If the method has any
references to
$this, it then fails with an E_FATAL, but otherwise it will run the
method as if
it were static.
This behavior is unexpected, and unintuitive. Calling non-static methods
as if
they were static, even when they do not reference $this, violates
visibility. I
would expect is_callable() to return false in these instances, and for
call_user_func() to immediately raise an E_FATAL if the method is not
defined as
static.
Test script:
---------------
class Foo
{
public function bar()
{
return 'foo bar';
}
}
$callback = array('Foo', 'bar');
if (is_callable($callback)) {
echo call_user_func($callback);
}
Expected result:
----------------
No output.
Actual result:
--------------
PHP Strict Standards: call_user_func() expects parameter 1 to be a
valid
callback, non-static method Foo::bar() should not be called statically
Strict Standards: call_user_func() expects parameter 1 to be a valid
callback,
non-static method Test\Foo::bar() should not be called statically
foo bar
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51527&edit=1