Commit 3e87610fe66 for php
commit 3e87610fe66b4a16533b04df4670a6481eeb101e
Author: Weilin Du <weilindu@php.net>
Date: Fri Nov 20 19:15:42 2026 +0800
SCCP: Fix constant propagation when unpacking into partial arrays (#25508)
diff --git a/NEWS b/NEWS
index 84b2777e258..ed8b3711ebe 100644
--- a/NEWS
+++ b/NEWS
@@ -104,6 +104,8 @@ PHP NEWS
(pavimus)
. Fixed opcache.enable_file_override lookups racing with OPcache restarts
(pavimus)
+ . Fixed incorrect constant propagation when unpacking into partially known
+ arrays. (Weilin Du)
- PDO_Firebird:
. Fixed stack buffer overflow with long connection user names, passwords,
diff --git a/Zend/Optimizer/sccp.c b/Zend/Optimizer/sccp.c
index ab863fd093d..b3f633ee226 100644
--- a/Zend/Optimizer/sccp.c
+++ b/Zend/Optimizer/sccp.c
@@ -540,6 +540,9 @@ static inline zend_result ct_eval_add_array_unpack(zval *result, zval *array) {
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 00000000000..0198ca263ea
--- /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)