[php-src] master: SCCP: Fold array_key_exists() with boolean and integral float keys (#25436)
| From: | Weilin Du via GitHub | Date: | Fri, 13 Nov 2026 17:14:25 +0000 |
| Subject: | [php-src] master: SCCP: Fold array_key_exists() with boolean and integral float keys (#25436) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143685@lists.php.net to get a copy of this message | ||
Author: Weilin Du (LamentXU123)
Committer: GitHub (web-flow)
Pusher: LamentXU123
Date: 2026-11-14T01:14:21+08:00
Commit: https://github.com/php/php-src/commit/6fe61c8c6ed4367d2e108d86f991571fae501c00
Raw diff: https://github.com/php/php-src/commit/6fe61c8c6ed4367d2e108d86f991571fae501c00.diff
SCCP: Fold array_key_exists() with boolean and integral float keys (#25436)
We can remove the extra key-type restriction in ct_eval_array_key_exists()
to allow SCCP to fold calls with boolean and integral float keys
Changed paths:
A ext/opcache/tests/opt/sccp_array_key_exists.phpt
M Zend/Optimizer/sccp.c
Diff:
diff --git a/Zend/Optimizer/sccp.c b/Zend/Optimizer/sccp.c
index 620cdd1f49f0..c62fabd54374 100644
--- a/Zend/Optimizer/sccp.c
+++ b/Zend/Optimizer/sccp.c
@@ -765,9 +765,6 @@ static inline zend_result ct_eval_array_key_exists(zval *result, const zval *op1
if (Z_TYPE_P(op2) != IS_ARRAY && !IS_PARTIAL_ARRAY(op2)) {
return FAILURE;
}
- if (Z_TYPE_P(op1) != IS_STRING && Z_TYPE_P(op1) != IS_LONG && Z_TYPE_P(op1) !=
IS_NULL) {
- return FAILURE;
- }
if (fetch_array_elem(&value, op2, op1) == FAILURE) {
return FAILURE;
}
diff --git a/ext/opcache/tests/opt/sccp_array_key_exists.phpt
b/ext/opcache/tests/opt/sccp_array_key_exists.phpt
new file mode 100644
index 000000000000..af45088d8da8
--- /dev/null
+++ b/ext/opcache/tests/opt/sccp_array_key_exists.phpt
@@ -0,0 +1,45 @@
+--TEST--
+SCCP: Evaluate array_key_exists with boolean and integral float keys, but not NAN or null
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+opcache.opt_debug_level=0x20000
+opcache.preload=
+--EXTENSIONS--
+opcache
+--FILE--
+<?php
+function test() {
+ var_dump(
+ array_key_exists(true, [1 => null]),
+ array_key_exists(false, [1 => null]),
+ array_key_exists(-1.0, [-1 => null]),
+ array_key_exists(2.0, [1 => null]),
+ array_key_exists(NAN, [0 => null]),
+ array_key_exists(null, ['' => null]),
+ );
+}
+?>
+--EXPECTF--
+$_main:
+ ; (lines=1, args=0, vars=0, tmps=0)
+ ; (after optimizer)
+ ; %s:%d-%d
+0000 RETURN int(1)
+
+test:
+ ; (lines=11, args=0, vars=0, tmps=1)
+ ; (after optimizer)
+ ; %s:%d-%d
+0000 INIT_FCALL 6 %d string("var_dump")
+0001 SEND_VAL bool(true) 1
+0002 SEND_VAL bool(false) 2
+0003 SEND_VAL bool(true) 3
+0004 SEND_VAL bool(false) 4
+0005 T0 = ARRAY_KEY_EXISTS float(%r[Nn][Aa][Nn]%r) array(...)
+0006 SEND_VAL T0 5
+0007 T0 = ARRAY_KEY_EXISTS null array(...)
+0008 SEND_VAL T0 6
+0009 DO_ICALL
+0010 RETURN null