Hi Bob, > I had this RFC in draft since some time, but delayed it due to all the > ongoing PHP 7 discussions. Also we have no master branch to merge features in > until 5.4 EOL. Thus I'm reviving this now. > > Time for the first RFC targeting PHP 7.1 (assuming PHP 8 isn't going to be > the next version ;-)): > > The short Closures RFC: > https://wiki.php.net/rfc/short_closures > > Hoping for constructive feedback, > Bob
Whilst I'd like to see a more expressive syntax for closures (and many other things) in PHP, I'm personally -1 on your proposal. The feature feels too inconsistent with the syntax and semantics of current PHP constructs for the following reasons: 1) The automatic binding of variables from the outer scope to the inner scope. 2) The optional use of parentheses for parameter definitions, but only when a single argument is used. 3) The optional use of braces for the function body, but only when a single expression is used. 4) The automatic returning of the expression, but only when it is alone, and only if the braces are omitted. These four differences create further special cases for people to learn and have no precedence in the language at all. They seem more like Rubyisms than PHPisms. Whilst we're on the topic of a terser syntax for closures though, Elixir has an even shorter syntax: &(&1 + &2) The &() denotes an closure definition; the &N is used to create placeholders, where N corresponds to the argument number. The ampersand obviously cannot be reused for this in PHP, but the dollar sign could: $func = $($1 + $2); var_dump($func(3, 4)); // int(7) This syntax should only be used in trivial scenarios, though, and comes with the disadvantage of no type information. Thanks, Tom -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php