|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47160 $foo() syntax is too limited
Submitted: 2009-01-20 08:57 UTC Modified: 2011-06-06 23:44 UTC
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: a at b dot c dot de Assigned: johannes (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.0alpha3 OS: Windows (irrelevant)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
26 + 37 = ?
Subscribe to this entry?

 [2009-01-20 08:57 UTC] a at b dot c dot de
It's already possible to have arrays that represent callable methods (either static or instance), and 5.3's closures offer a third type of "callable" function.

But the $foo() syntax that facilitates calling that callable function still requires $foo to contain a string.

Since in general one cannot know in advance just what type of callable the value of $foo actually is, and when one does know it's often NOT a string, it's necessary to forego the syntax and rely on call_user_func($foo).

What would be nice is if $foo() also worked in the cases where $foo was a callable array or Closure object. call_user_func() itself would largely be relegated to the status of "function equivalent should you need it" and complement to call_user_func_array().

Reproduce code:
// For 5.2.x as well.
class Thing {
    static function DoesStuff() {
        echo 'Hello, World';

$f = array('Thing', 'DoesStuff');


Expected result:
Hello, World

Actual result:
Fatal error: Function name must be a string in C:\test.php on line 11


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-28 21:48 UTC] dchurch at sciencelogic dot com
Closures in PHP 5.3 DO work like this, as they should.  But I agree that it should be possible to call array($object, 'methodname') or array('classname', 'staticmethod') in this fashion.
 [2010-12-22 13:55 UTC]
-Status: Open +Status: Assigned -Package: Feature/Change Request +Package: Scripting Engine problem -Assigned To: +Assigned To: johannes
 [2010-12-22 13:55 UTC]
This works fine w/ closures. Adding support for arrays might be worth in order to be consistent.
 [2011-06-06 23:42 UTC]
Automatic comment from SVN on behalf of felipe
Log: - Added indirect method call through array variable (FR Bug #47160)
 [2011-06-06 23:44 UTC]
-Status: Assigned +Status: Closed
 [2011-06-06 23:44 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

This feature has been implemented and committed in 5.4, trunk.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Feb 21 18:01:29 2024 UTC