Skip to content

PHP 8.4: PropertyReflector::getSettableType includes "?" in nullable identifier names. #19187

@BusterNeece

Description

@BusterNeece

Description

It appears that the type name returned by ReflectionProperty::getSettableType() will include the nullable question mark in the case of nullable values (i.e. ?string for string|null). This is inconsistent with existing behavior and the return type of ReflectionProperty::getType() given the same type hint.

The following code:

<?php
class Foo {
    public string|null $bar {
        set (string|null $value) => $value ?? 'default';
    }
}

$reflProp = new ReflectionProperty(Foo::class, 'bar');

echo $reflProp->getType()->getName();
echo $reflProp->getSettableType()->getName();

Resulted in this output:

string
?string

But I expected this output instead:

string
string

PHP Version

PHP 8.4.10 (cli) (built: Jul  3 2025 22:57:54) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.10, Copyright (c), by Zend Technologies
    with Xdebug v3.4.4, Copyright (c) 2002-2025, by Derick Rethans

Operating System

Debian Bookworm

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions