Short closures
thekid opened this issue · 2 comments
Currently, the compiler supports the Hack language variant, see https://docs.hhvm.com/hack/functions/anonymous-functions:
array_map((User $user) ==> $user->id, $users)
However, PHP 7.4 has decided to go a different way, introducing the fn
keyword in https://wiki.php.net/rfc/arrow_functions_v2, which makes it:
array_map(fn(User $user) => $user->id, $users)
The XP Compiler should adopt the latter.
We also have the compact method syntax which reuses the ==>
Operator:
class Person {
private string $name;
public function name() ==> $this->name;
}
This is supported neither by Hack nor by PHP but an idea that I borrowed from the original XP Compiler. The question is whether it should be rewritten to use fn
and the =>
operator for sake of consistency - see https://wiki.php.net/rfc/arrow_functions_v2#allow_arrow_notation_for_real_functions
The ==>
syntax should be deprecated in 2.X releases, and removed in 3.0.0