Description
The following code:
<?php
class A {
protected ?string $foo = null;
}
$a = new A();
$reflection = new ReflectionProperty($a, 'foo');
var_dump($reflection->getType());
Resulted in this output:
object(ReflectionNamedType)#3 (0) {
}
But I expected this output instead:
object(ReflectionUnionType)#3 (0) {
}
?string should be a union type, since it also equates to null|string, which also returns a ReflectionNameType instead of ReflectionUnionType. But, if I change the type to null|array|string, this results to ReflectionUnionType
PHP Version
PHP 8.4.1-dev
Operating System
No response