|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #64185 is_callable does not check syntax
Submitted: 2013-02-10 16:04 UTC Modified: 2013-02-13 19:52 UTC
From: hanskrentel at yahoo dot de Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5.4.11 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-02-10 16:04 UTC] hanskrentel at yahoo dot de
Using is_callable with the syntax_only parameter set to true does actually *not* 
check the syntax, for example of a valid classname or FQCN.

Also not for the method name.

My feature request is, that it will always check those strings according to the 
rules set in the PHP parser of the same PHP version the function ships with so 
that it can be used to validate PHP syntax as well.

Same for calls with :: for static class name method calls.

Test script:
var_dump(is_callable(['', ''], true));
var_dump(is_callable(['', 'method'], true));
var_dump(is_callable(['0', 'method'], true));
var_dump(is_callable(['0\\foo', 'method'], true));
var_dump(is_callable(['\\0\\foo', 'method'], true));

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-10 17:04 UTC] hanskrentel at yahoo dot de
NikiC was so friendly to just remind me that checking for the method name *is* limited because of __call and __callStatic (basically everything for a method name works, including a zero-length string).

So this feature request is actually more about the classname validation then the method name validation.
 [2013-02-13 14:40 UTC]
Even with classes such names could - theoretically - exist due to weird (3rd party) extensions etc. (i hope nobody does, but there's nothing stopping one)

So "syntax" in this case does not mean "one could use those names in syntactically correct PHP code" but "the overall structure matches something that might be used in a lookup"
 [2013-02-13 19:52 UTC]
Agree with what johannes said, marking as wontfix.
 [2013-02-13 19:52 UTC]
-Status: Open +Status: Wont fix
 [2013-05-11 10:01 UTC]
I just remembered that as of 5.4 you can actually create classes with arbitrary names from userland using class_alias. So that makes the second point moot too.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Sep 28 04:01:24 2023 UTC