php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51083 Closures returned by functions/methods must be stored to be executed...
Submitted: 2010-02-18 15:02 UTC Modified: 2014-10-12 14:48 UTC
Votes:4
Avg. Score:4.0 ± 1.7
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (66.7%)
From: adam dot jorgensen dot za at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.1 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: adam dot jorgensen dot za at gmail dot com
New email:
PHP Version: OS:

 

 [2010-02-18 15:02 UTC] 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 '('

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-06 12:17 UTC] 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-11-24 10:09 UTC] jani@php.net
-Package: Feature/Change Request +Package: Scripting Engine problem
 [2014-10-12 14:48 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2014-10-12 14:48 UTC] nikic@php.net
Supported in PHP 7.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 07:01:31 2025 UTC