1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix '?' in ReflectionNamedType::getName() from ReflectionProperty::getSettableType()

Fixes GH-19187
Closes GH-19201
This commit is contained in:
Ilija Tovilo
2025-07-21 15:38:34 +02:00
parent 441e55790f
commit 5a06842bf8
3 changed files with 63 additions and 3 deletions

4
NEWS
View File

@@ -11,6 +11,10 @@ PHP NEWS
. Add support for CURLINFO_CONN_ID in curl_getinfo() (thecaliskan)
. Add support for CURLINFO_QUEUE_TIME_T in curl_getinfo() (thecaliskan)
- Reflection:
. Fixed bug GH-19187 (ReflectionNamedType::getName() prints nullable type when
retrieved from ReflectionProperty::getSettableType()). (ilutov)
- Session:
. Fixed GH-19197: build broken with ZEND_STRL usage with memcpy
when implemented as macro. (David Carlier)

View File

@@ -6403,7 +6403,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;
}
@@ -6413,7 +6413,7 @@ 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;
}
@@ -6421,7 +6421,7 @@ ZEND_METHOD(ReflectionProperty, getSettableType)
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 */

View File

@@ -0,0 +1,56 @@
--TEST--
GH-19187: ReflectionNamedType::getName() should not include nullable type
--FILE--
<?php
class C {
public string|null $a {
set => $value;
}
public string|null $b {
set(string|null $value) => $value;
}
public string|null $c {
get => $this->c;
}
}
foreach ((new ReflectionClass(C::class))->getProperties() as $r) {
$type = $r->getType();
echo $type, "\n";
echo $type->getName(), "\n";
var_dump($type->allowsNull());
echo "\n";
$settableType = $r->getSettableType();
echo $settableType, "\n";
echo $settableType->getName(), "\n";
var_dump($settableType->allowsNull());
echo "\n";
}
?>
--EXPECT--
?string
string
bool(true)
?string
string
bool(true)
?string
string
bool(true)
?string
string
bool(true)
?string
string
bool(true)
?string
string
bool(true)