Req #52630 [Asn->Csd]: additional syntax for closures
| From: | nikic@php.net | Date: | Tue, 10 Mar 2015 21:18:18 +0000 |
| Subject: | Req #52630 [Asn->Csd]: additional syntax for closures | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-191297@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=52630&edit=1
ID: 52630
Updated by: nikic@php.net
Reported by: giorgio dot liscio at email dot it
Summary: additional syntax for closures
-Status: Assigned
+Status: Closed
Type: Feature/Change Request
Package: Variables related
Operating System: all
PHP Version: 5.3.3
Assigned To: stas
Block user comment: N
Private report: N
New Comment:
Implemented by https://wiki.php.net/rfc/uniform_variable_syntax
in PHP 7. Parentheses around the closure are required.
Previous Comments:
------------------------------------------------------------------------
[2010-09-02 00:06:33] stas@php.net
See http://wiki.php.net/rfc/fcallfcall
------------------------------------------------------------------------
[2010-08-18 01:02:18] kalle@php.net
I like the:
function($x) use($y) {return $x * $y;}(22);
approach, its consistent with that of other languages, like JavaScript
------------------------------------------------------------------------
[2010-08-17 22:41:04] 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
now:
$f = function($x) use($y){return $x * $y;};
$f(22);
request:
(function($x) use($y) {return $x * $y;})(22);
or
function($x) use($y) {return $x * $y;}(22);
or
function($x) use($y) invoke(22) {return $x * $y;};
etc
------------------------------------------------------------------------
[2010-08-17 22:21:17] kalle@php.net
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:17:26] giorgio dot liscio at email dot it
Description:
------------
hi, would be nice having this syntax for closures
$this->addResult
(
(
function ($param) use ($x) { return $x*$param; }
)($result)
);
a closure defined and executed in the same instruction, as JavaScript allows
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=52630&edit=1