xp-framework / core

The XP Framework is an all-purpose, object oriented PHP framework.
Other
19 stars 6 forks source link

Support reflective access to non-constant expressions for parameter defaults #259

Closed thekid closed 3 years ago

thekid commented 3 years ago

See https://github.com/xp-framework/compiler/pull/104#issuecomment-791924395, empowers the following when using the XP Compiler:

  #[Test]
  public function parameter_default_reflective_access() {
    $r= $this->run('use lang\ast\unittest\emit\Handle; class <T> {
      public function run($h= new Handle(0)) {
        return typeof($this)->getMethod("run")->getParameter(0)->getDefaultValue();
      }
    }');
    Assert::equals(new Handle(0), $r);
  }
thekid commented 3 years ago

This makes getDefaultValue() slower as it might need to parse the meta information. We can optimize this case though, because we don't want to support this from a XP "userland" perspective, only for the compiler, which eagerly prefills xp::$meta.

thekid commented 3 years ago

Released in https://github.com/xp-framework/core/releases/tag/v10.7.0