Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -6517,7 +6517,7 @@ ZEND_METHOD(ReflectionProperty, getSettableType)
/* Get-only virtual property can never be written to. */
if (prop->hooks && (prop->flags & ZEND_ACC_VIRTUAL) && !prop->hooks[ZEND_PROPERTY_HOOK_SET]) {
zend_type never_type = ZEND_TYPE_INIT_CODE(IS_NEVER, 0, 0);
reflection_type_factory(never_type, return_value, 0);
reflection_type_factory(never_type, return_value, 1);
return;
}

Expand All @@ -6527,15 +6527,15 @@ ZEND_METHOD(ReflectionProperty, getSettableType)
if (!ZEND_TYPE_IS_SET(arg_info->type)) {
RETURN_NULL();
}
reflection_type_factory(arg_info->type, return_value, 0);
reflection_type_factory(arg_info->type, return_value, 1);
return;
}

/* Fall back to property type */
if (!ZEND_TYPE_IS_SET(ref->prop->type)) {
RETURN_NULL();
}
reflection_type_factory(ref->prop->type, return_value, 0);
reflection_type_factory(ref->prop->type, return_value, 1);
}

/* {{{ Returns whether property has a type */
Expand Down
19 changes: 19 additions & 0 deletions ext/reflection/tests/gh19187.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
GH-19187: ReflectionNamedType::getName() should not include nullable type
--FILE--
<?php

class Foo {
public string|null $bar {
set(string|null $value) => $value;
}
}

$reflProp = new ReflectionProperty(Foo::class, 'bar');
echo $reflProp->getType()->getName(), "\n";
echo $reflProp->getSettableType()->getName(), "\n";

?>
--EXPECT--
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, can you also include the output of __toString() and allowsNull() to confirm that the nullability is still communicated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also added a test for the fallback path when no set is present.

string
string