[php-src] master: Avoid unnecessary concatenation in `zend_named_reflection_type_to_string()`

Daniel Scherzer <[email protected]>
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Daniel Scherzer (DanielEScherzer)
Date: 2026-07-07T10:33:40-07:00

Commit: https://github.com/php/php-src/commit/6a19160ca561c2ae11313d98105db3f4a0598276
Raw diff: https://github.com/php/php-src/commit/6a19160ca561c2ae11313d98105db3f4a0598276.diff

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.

Changed paths:
  M  ext/reflection/php_reflection.c


Diff:

diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 5d5c8eaeb038..8d409a127b81 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);
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.