xp-framework / compiler

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

Add support for annotations in anonymous classes #73

Closed thekid closed 5 years ago

thekid commented 5 years ago

Example:

$instance= new class() {

  <<test>>
  public function fixture() { }
};

$annotations= typeof($instance)->getMethod('fixture')->getAnnotations();
// ['test' => null]

See also xp-framework/core#226

thekid commented 5 years ago

Maybe instead of constructor rewriting, we could do something like:

$c= new class() {
  #[@test]
  public function fixture();
};

// ...becomes
$c= (new class() {

  public function fixture();

  public function __init() { \xp::$meta[strtr(self::class, '\\', '.')]= ...; return $this; }
})->__init();
thekid commented 5 years ago

:shipit: Released in https://github.com/xp-framework/compiler/releases/tag/v4.1.0