-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Description
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