Am 31.01.2017 um 05:53 schrieb Stephen Reay:
Hi Andrea, All,

On 31 Jan 2017, at 08:12, Andrea Faulds <a...@ajf.me> wrote:

Is it necessary to introduce a new keyword, fn?

I think you'd get a similar benefit from:

   function($x) => $arr[$x]

Likewise, is it necessary to restrict auto-capture to the => syntax? Couldn't 
we allow the following?

   function ($x) {
       return $arr[$x];
   }


I agree that the `fn` keyword isn’t really necessary. I’ve never quite 
understood how arrow functions with implied returns etc are supposed to make 
for *more* readable code, but if they’re going to be part of the language 
please at least keep some consistency with regular closures.

In the case that regular closures got auto-capture, would a `use($foo, $bar, 
$baz)` segment on a closure still be honoured (i.e. disable auto-capture), and 
would it have any impact (positive or negative) on performance/memory usage? 
After several years of JS closure ‘fun’ I kind of like that with PHP you only 
inherit the variables you explicitly `use()` in closures.

I like the general idea, too. But with similar feelings for:
- Introducing a second keyword for closures is confusing - and mor confusing if they are basically the same words

- Also I like the "use"  keyword you have to define your variables

-> Would it be helpful to allow "function () use (*) {}" to inline all available variables?

- Or based on Rowans idea to stretching the brackets but using the function keyword:

    function($x => $arr[$x])

Thanks
Marc


Cheers

Stephen


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to