xp-framework / compiler

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

Implement first class callable syntax for instance method references #164

Closed thekid closed 9 months ago

thekid commented 1 year ago

Inspired by https://externals.io/message/120011


class Person {
  public function __construct(private string $name) { }
  public function name(): string { return $this->name; }
}

$group= [new Person('Timm'), new Person('Alex')];

// Instead of the following:
$names= array_map(fn($person) => $person->name(), $group);

// ...we can now write this:
$names= array_map(Person->name(...), $group);

// ["Timm", "Alex"]