Edit report at https://bugs.php.net/bug.php?id=54243&edit=1
ID: 54243 Comment by: ninzya at inbox 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: I think the proposed syntax is not readable at all. Rather it looks like you have been affected by a "wannabe jQuery inventor". How do you come up with a dollar sign being "readable"? How do you define "readable code"? If you read your code, you read it as "dollar, dollar, bracket, dollar, dollar... whatever, dollar". Is this what you call "readability"? However I do agree that the "use()" clause of closures sometimes bloats the code a little bit, especially if the closure is importing a lot of variables from its context. Previous Comments: ------------------------------------------------------------------------ [2012-03-19 09:08:09] danko at very dot lv 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. ------------------------------------------------------------------------ [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