hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

ReflectionParam->getClass() returns null with nullable typehint

Open HRMsimon opened this issue 11 years ago • 1 comments

<?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)

HRMsimon avatar Aug 19 '15 04:08 HRMsimon

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

paulbiss avatar Aug 19 '15 18:08 paulbiss