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