Commit 6a19160ca56 for php.net
commit 6a19160ca561c2ae11313d98105db3f4a0598276
Author: Daniel Scherzer <daniel.e.scherzer@gmail.com>
Date: Thu Jul 2 11:03:32 2026 -0700
Avoid unnecessary concatenation in `zend_named_reflection_type_to_string()`
When a type corresponds to an iterator that may be null, the string
representation is known ahead of time to be "?iterable". Use
`ZSTR_INIT_LITERAL()` rather than building up a string with
`zend_string_concat2()` from a "?" and the "iterable" known string.
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 5d5c8eaeb03..8d409a127b8 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -3074,11 +3074,10 @@ ZEND_METHOD(ReflectionType, allowsNull)
/* For BC with iterable for named types */
static zend_string *zend_named_reflection_type_to_string(zend_type type) {
if (ZEND_TYPE_IS_ITERABLE_FALLBACK(type)) {
- zend_string *iterable = ZSTR_KNOWN(ZEND_STR_ITERABLE);
if (ZEND_TYPE_FULL_MASK(type) & MAY_BE_NULL) {
- return zend_string_concat2("?", strlen("?"), ZSTR_VAL(iterable), ZSTR_LEN(iterable));
+ return ZSTR_INIT_LITERAL("?iterable", false);
}
- return iterable;
+ return ZSTR_KNOWN(ZEND_STR_ITERABLE);
}
return zend_type_to_string(type);
}