Skip to content

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

Closed

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

Activity

  1. self-assigned this
    on Jul 21, 2025
  2. added a commit that references this issue on Jul 21, 2025
    5f80c87
  3. added a commit that references this issue on Jul 22, 2025
    5a06842
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions