From: weierophinney
Operating system: Linux
PHP version: 5.3.2
Package: Class/Object related
Bug Type: Bug
Bug description:is_callable() returning true for non-static callbacks
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 bug report at http://bugs.php.net/bug.php?id=51527&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=51527&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=51527&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=51527&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=51527&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=51527&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=51527&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=51527&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=51527&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=51527&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=51527&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=51527&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=51527&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=51527&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=51527&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51527&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=51527&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=51527&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=51527&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=51527&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=51527&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=51527&r=mysqlcfg