Bug->Doc #70088 [Opn]: is_callable() doesn't check if a class/method syntax is valid
| From: | cmb@php.net | Date: | Thu, 16 Jul 2015 15:59:29 +0000 |
| Subject: | Bug->Doc #70088 [Opn]: is_callable() doesn't check if a class/method syntax is valid | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-12529@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70088&edit=1
ID: 70088
Updated by: cmb@php.net
Reported by: olivier dot laviale at gmail dot com
Summary: is_callable() doesn't check if a class/method syntax
is valid
Status: Open
-Type: Bug
+Type: Documentation Problem
-Package: Scripting Engine problem
+Package: Variables related
Operating System: MacOS, Linux
PHP Version: 5.6.11
Block user comment: N
Private report: N
New Comment:
> Unless '+{^not&a*callable}' is a valid function name.
Well, this is a valid function name, e.g.
$func = '+{^not&a*callable}';
runkit_function_copy('strlen', $func);
$func('foo'); // => 3
is_callable($func, false); // => true
If is_callable($func, false) may return true, is_callable($func,
true) should never return false.
> Also, I strongly believe that "syntax_only" is misleading.
ACK. Therefore I'm changing to doc bug.
Previous Comments:
------------------------------------------------------------------------
[2015-07-16 13:50:39] olivier dot laviale at gmail dot com
Yes, you can invoke methods with invalid names if __call() is implemented, I don't think
it's right, but that's a fact. My point is that the following code should return
false:
var_dump(is_callable('+{^not&a*callable}', true, $callable_name));
Unless '+{^not&a*callable}' is a valid function name.
Also, I strongly believe that "syntax_only" is misleading. This is not syntax check, this
is type check: a string, or an array with two values.
------------------------------------------------------------------------
[2015-07-16 13:33:05] ab@php.net
Maybe it could be improved if we check whether an object has __call() defined. But if it has
__call() - there's no chance to know exactly what is callable, say this would work
$obj->{"+{^not&a*callable}"}();. But I'd rather tend to say it is not a bug.
Thanks.
------------------------------------------------------------------------
[2015-07-16 12:53:41] olivier dot laviale at gmail dot com
Description:
------------
is_callable(), with _syntax_only_ activated, only checks the type of the argument, not the actual
syntax. For example "+{^not&a*callable}" is considered a callable just because it is a
string.
I saw this bug report: https://bugs.php.net/bug.php?id=64185&edit=2,
and I get it for class names, but what about function/method names?
"+{^not&a*callable}" is definitely not a callable, or the parameter
"syntax_only" is incredibly misleading.
Test script:
---------------
var_dump(is_callable('+{^not&a*callable}', true, $callable_name));
var_dump($callable_name);
var_dump(is_callable(123, true));
var_dump(is_callable("123", true));
var_dump(is_callable([ "1", "2" ], true));
Expected result:
----------------
"+{^not&a*callable}" shouldn't be considred as a callable, neither
should [ "1", "2" ].
bool(false)
null
bool(false)
bool(false)
bool(false)
Actual result:
--------------
bool(true)
string(18) "+{^not&a*callable}"
bool(false)
bool(true)
bool(true)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70088&edit=1