Req #54243 [Com]: Shorter syntax for closures
| From: | danko at very dot lv | Date: | Mon, 19 Mar 2012 09:08:09 +0000 |
| Subject: | Req #54243 [Com]: Shorter syntax for closures | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-168597@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=54243&edit=1
ID: 54243
Comment by: danko at very dot lv
Reported by: anil at saog dot net
Summary: Shorter syntax for closures
Status: Open
Type: Feature/Change Request
Package: *General Issues
Operating System: *
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Um, no, *that* is unreadable. The original syntax can easily be made readable if you do care:
$myObject->MyMethod(
'abc',
function ($a) use ($b) {
return $a == $b;
}
);
There you go. As readable as it gets - just add some newlines and tabs. On the other hand, a soup of
brackets and dollar signs can't be readable regardless of formatting.
Previous Comments:
------------------------------------------------------------------------
[2011-03-13 16:16:45] anil at saog dot net
Changed package
------------------------------------------------------------------------
[2011-03-13 16:09:36] anil at saog dot net
Description:
------------
Current closure syntax makes the code a little bit unreadable and also shortening the syntax of a
handy thing like this seems more logical.
Test script:
---------------
As of now "closure" syntax is:
function ($a) use($b){ return $a == $b; }
Passing a closure to any other scope:
$myObject = new myObject ();
$myObject->MyMethod('abc', function ($a) use($b){ return $a == $b; });
Expected result:
----------------
My short syntax candidate is:
$([arg1],[arg2],[arg...], {[method body]}, [scope_var1],[scope_var2],[scope_var...])
So passing with use token syntax:
$myObject = new myObject ();
$myObject->MyMethod('abc', $($a, {$a == $b}, $b));
Without "use" token:
$myObject = new myObject ();
$myObject->MyMethod('abc', $($a, {$a == $b}));
With more than one method argument:
$myObject = new myObject ();
$myObject->MyMethod('abc', $($a,$k,$p,{$a == $b}));
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=54243&edit=1