Bug #72084 [NEW]: is_callable returns true for array with class and non static method
| From: | heah at heahprod dot com | Date: | Sat, 23 Apr 2016 03:53:24 +0000 |
| Subject: | Bug #72084 [NEW]: is_callable returns true for array with class and non static method | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-200703@lists.php.net to get a copy of this message | ||
From: heah at heahprod dot com
Operating system: os X 10.11.4
PHP version: 5.6.20
Package: Reproducible crash
Bug Type: Bug
Bug description:is_callable returns true for array with class and non static method
Description:
------------
Hi,
documentation says that valid callables might be string name of
functions, closure, or:
"A method of an instantiated object is passed as an array containing an
object at index 0 and the method name at index 1. Accessing protected
and private methods from within a class is allowed.
Static class methods can also be passed without instantiating an object
of that class by passing the class name instead of an object at index 0.
As of PHP 5.2.3, it is also possible to pass 'ClassName::methodName'."
ref http://php.net/manual/en/language.types.callable.php
However "is_callable" does not behave as I would expect when passing an
array with a class and a non static method, true is returned instead of
false.
Is this an expected behavior? Shouldn't we rely on "is_callable" before
calling "call_user_func"?
If not please update or let me know if I should open another issue for:
http://php.net/manual/en/function.is-callable.php
since it currently says:
"Verify that the contents of a variable can be called as a function.
This can check that a simple variable contains the name of a valid
function, or that an array contains a properly encoded object and
function name."
If we change the test script I provide to "echo" a regular string like
"object call" instead of using an object property, the string is printed
after the warning triggered by "is_callable", so "call_user_func" is
actually called.
Since I'm just a php beginner and don't know anything about the
internal, I don't know if the error comes with "is_callable" because
"call_user_func" is actually callable or if it comes from
"call_user_func" because "is_callable" returns true.
But my guess is that "call_user_func" should test internally if the
array is callable (second case), and throw an invalid argument exception
instead.
The a user like me should be able to use "is_callable" before using it
and getting the invalid argument exception.
However the current fatal error got from the provided test script looks
really wrong to me.
Note that it happens in my local environment but not on my server
holding the script online.
Thank you for your time reading this and for working on PHP, it is an
awesome open-source project!
(sorry for any mistake, this is my first issue report and I'm not a
native speaker).
Test script:
---------------
http://heahprod.com/php/bug-is_callable.php
Expected result:
----------------
static call static call object call object message
Actual result:
--------------
static call
Strict Standards: call_user_func() expects parameter 1 to be a valid
callback, non-static method SomeClass::someObjectMethod() should not be
called statically in /test.php on line 39
object call
Strict Standards: call_user_func() expects parameter 1 to be a valid
callback, non-static method SomeClass::getMessage() should not be called
statically in /test.php on line 45
Fatal error: Using $this when not in object context in /test.php on line
19
--
Edit bug report at https://bugs.php.net/bug.php?id=72084&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72084&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72084&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72084&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72084&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72084&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72084&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72084&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72084&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72084&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72084&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72084&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72084&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72084&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72084&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72084&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72084&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72084&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72084&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72084&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72084&r=mysqlcfg