Req #47160 [Asn->Csd]: $foo() syntax is too limited

From: Date: Mon, 06 Jun 2011 21:44:27 +0000
Subject: Req #47160 [Asn->Csd]: $foo() syntax is too limited
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-161220@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=47160&edit=1

 ID:                 47160
 Updated by:         felipe@php.net
 Reported by:        a at b dot c dot de
 Summary:            $foo() syntax is too limited
-Status:             Assigned
+Status:             Closed
 Type:               Feature/Change Request
 Package:            Scripting Engine problem
 Operating System:   Windows (irrelevant)
 PHP Version:        5.3.0alpha3
 Assigned To:        johannes
 Block user comment: N
 Private report:     N

 New Comment:

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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

This feature has been implemented and committed in 5.4, trunk.


Previous Comments:
------------------------------------------------------------------------
[2011-06-06 23:42:07] felipe@php.net

Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&revision=311871
Log: - Added indirect method call through array variable (FR Bug #47160)

------------------------------------------------------------------------
[2010-12-22 13:55:50] johannes@php.net

This works fine w/ closures. Adding support for arrays might be worth in order to be consistent.

------------------------------------------------------------------------
[2010-05-28 21:48:06] 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.

------------------------------------------------------------------------
[2009-01-20 08:57:09] a at b dot c dot de

Description:
------------
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:
---------------
<?php
// For 5.2.x as well.
class Thing {
    static function DoesStuff() {
        echo 'Hello, World';
    }
}

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

$f();
?>

Expected result:
----------------
Hello, World

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



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=47160&edit=1


Thread (4 messages)

« previous php.bugs (#161220) next »