Req #51083 [Opn->Csd]: Closures returned by functions/methods must be stored to be executed...
| From: | nikic@php.net | Date: | Sun, 12 Oct 2014 14:48:43 +0000 |
| Subject: | Req #51083 [Opn->Csd]: Closures returned by functions/methods must be stored to be executed... | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188035@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=51083&edit=1
ID: 51083
Updated by: nikic@php.net
Reported by: adam dot jorgensen dot za at gmail dot com
Summary: Closures returned by functions/methods must be
stored to be executed...
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 5.3.1
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Supported in PHP 7.
Previous Comments:
------------------------------------------------------------------------
[2010-03-06 12:17:02] kalle@php.net
Function call chaining is not supported in any versions of php, its was however
decided at the May 2009 PDM to implement it together with array dereferencing in
PHP6.
------------------------------------------------------------------------
[2010-02-18 15:02:43] adam dot jorgensen dot za at gmail dot com
Description:
------------
When returning an anonymous function from a method or function call, the returned closure is not
directly executable in a logical fashion. The closure needs to be stored in order to be executed or
must be called via the call_user_func family of functions.
This is fairly illogical and inconsistent with the idea of closures.
Reproduce code:
---------------
function test($a)
{
return function($b) use($a) { echo $a . ':' . $b . '<br/>'; };
}
call_user_func(test(1), 2);
$x = test(1);
$x(2);
test(1)(2);
Expected result:
----------------
Output should be:
1:2
1:2
1:2
Actual result:
--------------
Execution fails. Error:
PHP Parse error: syntax error, unexpected '('
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=51083&edit=1