hhvm
hhvm copied to clipboard
ReflectionParam->getClass() returns null with nullable typehint
<?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)
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