Commit 710581b074b for php
commit 710581b074b2cd000371db1440cc976ca8fb38c6
Author: fQwQf <supertjz123@foxmail.com>
Date: Sun Dec 6 20:36:14 2026 +0100
Zend/Optimizer: Keep runtime deprecations in SCCP for ASSIGN_DIM (GH-26056)
`ct_eval_add_array_elem()` handled an `IS_NULL` key by silently inserting
under the `""` key, and `ct_eval_assign_dim()` handled `IS_FALSE` by
silently initializing an array. Both drop the runtime deprecations:
- "Using null as an array offset is deprecated"
- "Automatic conversion of false to array is deprecated"
Fix by returning `FAILURE` for these cases, mirroring the existing guard
for `IS_DOUBLE` and the bailout pattern in `INIT_ARRAY`/`ADD_ARRAY_ELEMENT`.
Closes GH-26056
diff --git a/NEWS b/NEWS
index 98358978d2c..80f41c20a4d 100644
--- a/NEWS
+++ b/NEWS
@@ -38,6 +38,8 @@ PHP NEWS
element removed by DCE. (fQwQf)
. Fixed $i++ < $n being optimized to ++$i <= $n for non-integer operands or
on integer overflow. (ChrisAbner)
+ . Fixed SCCP dropping "Using null as an array offset" and "Automatic
+ conversion of false to array" deprecations for ASSIGN_DIM. (fQwQf)
- Reflection:
. Fixed bug GH-24729 (Use-after-free in
diff --git a/Zend/Optimizer/sccp.c b/Zend/Optimizer/sccp.c
index 671b1cf5cdd..7efdda7566b 100644
--- a/Zend/Optimizer/sccp.c
+++ b/Zend/Optimizer/sccp.c
@@ -495,9 +495,9 @@ static inline zend_result ct_eval_add_array_elem(zval *result, zval *value, cons
switch (Z_TYPE_P(key)) {
case IS_NULL:
- SEPARATE_ARRAY(result);
- value = zend_hash_update(Z_ARR_P(result), ZSTR_EMPTY_ALLOC(), value);
- break;
+ /* "Using null as an array offset is deprecated" is emitted at
+ * run-time. */
+ return FAILURE;
case IS_FALSE:
SEPARATE_ARRAY(result);
value = zend_hash_index_update(Z_ARR_P(result), 0, value);
@@ -560,12 +560,15 @@ static inline zend_result ct_eval_add_array_unpack(zval *result, zval *array) {
static inline zend_result ct_eval_assign_dim(zval *result, zval *value, const zval *key) {
switch (Z_TYPE_P(result)) {
case IS_NULL:
- case IS_FALSE:
array_init(result);
ZEND_FALLTHROUGH;
case IS_ARRAY:
case PARTIAL_ARRAY:
return ct_eval_add_array_elem(result, value, key);
+ case IS_FALSE:
+ /* "Automatic conversion of false to array is deprecated" is
+ * emitted at run-time. */
+ return FAILURE;
case IS_STRING:
// TODO Before enabling this case, make sure ARRAY_DIM result op is correct
#if 0
diff --git a/ext/opcache/tests/opt/sccp_assign_dim_null_key.phpt b/ext/opcache/tests/opt/sccp_assign_dim_null_key.phpt
new file mode 100644
index 00000000000..acee8d9f6e2
--- /dev/null
+++ b/ext/opcache/tests/opt/sccp_assign_dim_null_key.phpt
@@ -0,0 +1,45 @@
+--TEST--
+SCCP must keep runtime deprecations for ASSIGN_DIM with null key and false autovivification
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.jit=0
+--EXTENSIONS--
+opcache
+--FILE--
+<?php
+set_error_handler(function($no, $str) { echo "H:$str\n"; return true; });
+function f1() { $a = []; $q = $a; $q[null] = 99; return $a === $q; }
+function f2() { $a = []; $a[null] = 'v'; return $a; }
+function f3() { $s = false; $s[null] = 'v'; return $s; }
+function f4() { $s = false; $s[0] = 'v'; return $s; }
+function f5() { $s = false; $s[] = 'v'; return $s; }
+var_dump(f1());
+var_dump(f2());
+var_dump(f3());
+var_dump(f4());
+var_dump(f5());
+--EXPECTF--
+H:Using null as an array offset is deprecated, use an empty string instead
+bool(false)
+H:Using null as an array offset is deprecated, use an empty string instead
+array(1) {
+ [""]=>
+ string(1) "v"
+}
+H:Automatic conversion of false to array is deprecated
+H:Using null as an array offset is deprecated, use an empty string instead
+array(1) {
+ [""]=>
+ string(1) "v"
+}
+H:Automatic conversion of false to array is deprecated
+array(1) {
+ [0]=>
+ string(1) "v"
+}
+H:Automatic conversion of false to array is deprecated
+array(1) {
+ [0]=>
+ string(1) "v"
+}