Skip to content

?string should return ReflectionUnionType instead of ReflectionType #17756

@donjajo

Description

@donjajo

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions