3 ms·
I wish they implemented them like in JS without the unnecessary fn().
by bufferoverflow 7y ago
I wish they implemented them like in JS without the unnecessary fn().
- Denvercoder9 7y agoThat would give syntactic ambiguity, since the => operator is also used to separate keys and values in array notation.
- _rs 7y agoFair, but seems inconsistent to have `fn` instead of `function` like we use for anonymous functions - unless `fn` acts like an alias to `function` now (which doesn't sound like is the case) which wouldn't be as ambiguous for the compiler to figure out
- bufferoverflow 7y agoI don't think there's an ambiguity, since the key-value application of that operator only happens inside the array definition or when you do foreach ($x as $k => $v) {}.
- TimothyBJacobs 7y agoThere is ambiguity. This was specifically mentioned in the RFC for the feature: https://wiki.php.net/rfc/arrow_functions_v2#syntax https://wiki.php.net/rfc/arrow_functions_v2#syntax
- Izkata 7y agoIt does if you're trying to make an array of anonymous functions...