facebook / hhvm

A virtual machine for executing programs written in Hack.
https://hhvm.com
Other
18.16k stars 2.99k forks source link

ReflectionParam->getClass() returns null with nullable typehint #6064

Open HRMsimon opened 9 years ago

HRMsimon commented 9 years ago
<?hh

class A {
  public function b(?A $c) {}
}

var_dump((new ReflectionMethod('A', 'b'))->getParameters()[0]->getClass());

Outputs null when it should be returning a ReflectionClass instance of A (as it does without the nullability type hint)

paulbiss commented 9 years ago

This would appear to be intentional, we seem to forgo setting the type field for any non-vanilla-PHP type annotation, which would cause getClass to be null:

    auto const nonExtendedConstraint =
      fpi.typeConstraint.hasConstraint() &&
      !fpi.typeConstraint.isExtended();
    auto const type = nonExtendedConstraint ? fpi.typeConstraint.typeName()
      : staticEmptyString();

https://github.com/facebook/hhvm/blob/f61be04092e7ea69c5476c7a2c89cd7840ebffcc/hphp/runtime/ext/reflection/ext_reflection.cpp#L644-L648