|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52630 additional syntax for closures
Submitted: 2010-08-17 22:17 UTC Modified: 2015-03-10 21:18 UTC
Avg. Score:4.6 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: giorgio dot liscio at email dot it Assigned: stas (profile)
Status: Closed Package: Variables related
PHP Version: 5.3.3 OS: all
Private report: No CVE-ID: None
 [2010-08-17 22:17 UTC] giorgio dot liscio at email dot it
hi, would be nice having this syntax for closures

        function ($param) use ($x) { return $x*$param; }

a closure defined and executed in the same instruction, as JavaScript allows


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-17 22:21 UTC]
-Assigned To: +Assigned To: stas
 [2010-08-17 22:21 UTC]
I belive stas' had a patch for this? Or atleast function call chaining, but I assume if implemented it would allow this syntax?
 [2010-08-17 22:41 UTC] giorgio dot liscio at email dot it
any alternative syntax can be good if the result is the same, defining end invoking on the same instruction without using any var


$f = function($x) use($y){return $x * $y;};


(function($x) use($y) {return $x * $y;})(22);


function($x) use($y) {return $x * $y;}(22);


function($x) use($y) invoke(22) {return $x * $y;};

 [2010-08-18 01:02 UTC]
I like the:
function($x) use($y) {return $x * $y;}(22);

approach, its consistent with that of other languages, like JavaScript
 [2010-09-02 00:06 UTC]
-Status: Assigned +Status: Open -Type: Bug +Type: Feature/Change Request
 [2015-03-10 21:18 UTC]
-Status: Assigned +Status: Closed
 [2015-03-10 21:18 UTC]
Implemented by in PHP 7. Parentheses around the closure are required.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Sep 24 16:03:41 2021 UTC