Re: Re: [RFC][Discuss] Arrow Functions
| From: | Marc Bennewitz | Date: | Tue, 31 Jan 2017 05:44:25 +0000 |
| Subject: | Re: Re: [RFC][Discuss] Arrow Functions | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98062@lists.php.net to get a copy of this message | ||
Am 31.01.2017 um 05:53 schrieb Stephen Reay:
Hi Andrea, All,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 variablesOn 31 Jan 2017, at 08:12, Andrea Faulds <ajf@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) {I agree that thereturn $arr[$x];}fnkeyword 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 ause($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 explicitlyuse()in closures.
-> 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