Commit c89e3df7646 for php.net
commit c89e3df7646cc4feeb7b9b6d7a6cf270d0d0e556
Author: Daniel Scherzer <daniel.e.scherzer@gmail.com>
Date: Thu Jul 2 12:52:00 2026 -0700
`ReflectionNamedType::getName()`: inline logic for legacy behavior
Instead of a single-use two-line helper function
`zend_type_to_string_without_null()`, move the relevant logic into
`ReflectionNamedType::getName()` directly. To maintain the behavior of removing
the `MAY_BE_NULL` flag from a *copy* of the stored type information, make an
explicit copy of the type before the flag is removed.
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 0a670c856eb..271a4aae6e0 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -3080,11 +3080,6 @@ static zend_string *zend_named_reflection_type_to_string(zend_type type) {
return zend_type_to_string(type);
}
-static zend_string *zend_type_to_string_without_null(zend_type type) {
- ZEND_TYPE_FULL_MASK(type) &= ~MAY_BE_NULL;
- return zend_named_reflection_type_to_string(type);
-}
-
/* {{{ Return the text of the type hint */
ZEND_METHOD(ReflectionType, __toString)
{
@@ -3107,10 +3102,12 @@ ZEND_METHOD(ReflectionNamedType, getName)
ZEND_PARSE_PARAMETERS_NONE();
GET_REFLECTION_OBJECT_PTR(param);
+ // Make a copy so that we don't modify the stored type information
+ zend_type type = param->type;
if (param->legacy_behavior) {
- RETURN_STR(zend_type_to_string_without_null(param->type));
+ ZEND_TYPE_FULL_MASK(type) &= ~MAY_BE_NULL;
}
- RETURN_STR(zend_named_reflection_type_to_string(param->type));
+ RETURN_STR(zend_named_reflection_type_to_string(type));
}
/* }}} */