[php-src] master: Merge branch 'PHP-8.6'
| From: | Arnaud Le Blanc | Date: | Fri, 20 Nov 2026 11:16:43 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143966@lists.php.net to get a copy of this message | ||
Author: Arnaud Le Blanc (arnaud-lb)
Date: 2026-11-20T12:16:05+01:00
Commit: https://github.com/php/php-src/commit/75679b1eeee47af1cdb0c0a4852e3dd8c7c88e81
Raw diff: https://github.com/php/php-src/commit/75679b1eeee47af1cdb0c0a4852e3dd8c7c88e81.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
SCCP: Fix constant propagation when unpacking into partial arrays (#25508)
Changed paths:
A ext/opcache/tests/opt/sccp_array_unpack_partial.phpt
M Zend/Optimizer/sccp.c
Diff:
diff --git a/Zend/Optimizer/sccp.c b/Zend/Optimizer/sccp.c
index c62fabd54374..e3db09d7fea4 100644
--- a/Zend/Optimizer/sccp.c
+++ b/Zend/Optimizer/sccp.c
@@ -560,6 +560,9 @@ static inline zend_result ct_eval_add_array_unpack(zval *result, const zval *arr
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(array), key, value) {
if (key) {
value = zend_hash_update(Z_ARR_P(result), key, value);
+ } else if (IS_PARTIAL_ARRAY(result)) {
+ /* The next free index of a partial array is unknown. */
+ continue;
} else {
value = zend_hash_next_index_insert(Z_ARR_P(result), value);
}
diff --git a/ext/opcache/tests/opt/sccp_array_unpack_partial.phpt
b/ext/opcache/tests/opt/sccp_array_unpack_partial.phpt
new file mode 100644
index 000000000000..0198ca263ea7
--- /dev/null
+++ b/ext/opcache/tests/opt/sccp_array_unpack_partial.phpt
@@ -0,0 +1,40 @@
+--TEST--
+SCCP must not infer numeric keys when unpacking into a partial array
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+opcache.jit=0
+--EXTENSIONS--
+opcache
+--FILE--
+<?php
+function test($unknown) {
+ $array = [$unknown, ...[42]];
+ var_dump($array[0], $array[1]);
+
+ $array = [10, $unknown, ...[42, 43]];
+ var_dump($array[0], $array[1], $array[2], $array[3]);
+
+ $array = [100 => $unknown, ...[42]];
+ var_dump($array[0] ?? 'missing', $array[100], $array[101]);
+
+ $array = [$unknown, 'key' => 0, ...[42, 'key' => 43], 44];
+ var_dump($array[0], $array[1], $array[2], $array['key']);
+}
+test(7);
+?>
+--EXPECT--
+int(7)
+int(42)
+int(10)
+int(7)
+int(42)
+int(43)
+string(7) "missing"
+int(7)
+int(42)
+int(7)
+int(42)
+int(44)
+int(43)