xp-framework / compiler

Compiles future PHP to today's PHP.
19 stars 0 forks source link

Short closures #60

Closed thekid closed 5 years ago

thekid commented 5 years ago

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.

thekid commented 5 years ago

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

thekid commented 5 years ago

The ==> syntax should be deprecated in 2.X releases, and removed in 3.0.0