From 032101262554cf49586b7cb59b3e1fa5ca835007 Mon Sep 17 00:00:00 2001 From: Weilin Du Date: Fri, 13 Nov 2026 13:02:32 +0800 Subject: [PATCH 1/2] SCCP: Fold array_key_exists() with boolean and integral float keys --- Zend/Optimizer/sccp.c | 3 -- .../tests/opt/sccp_array_key_exists.phpt | 39 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 ext/opcache/tests/opt/sccp_array_key_exists.phpt 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..b2c03419350f --- /dev/null +++ b/ext/opcache/tests/opt/sccp_array_key_exists.phpt @@ -0,0 +1,39 @@ +--TEST-- +SCCP: Evaluate array_key_exists with boolean and integral float keys +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +opcache.opt_debug_level=0x20000 +opcache.preload= +--EXTENSIONS-- +opcache +--FILE-- + null]), + array_key_exists(false, [1 => null]), + array_key_exists(-1.0, [-1 => null]), + array_key_exists(2.0, [1 => null]), + ); +} +?> +--EXPECTF-- +$_main: + ; (lines=1, args=0, vars=0, tmps=0) + ; (after optimizer) + ; %s:%d-%d +0000 RETURN int(1) + +test: + ; (lines=7, args=0, vars=0, tmps=0) + ; (after optimizer) + ; %s:%d-%d +0000 INIT_FCALL 4 %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 DO_ICALL +0006 RETURN null From 91a6bed4a3a07265a613790bb7a2cbe4c559c2c5 Mon Sep 17 00:00:00 2001 From: Weilin Du Date: Sat, 14 Nov 2026 00:47:18 +0800 Subject: [PATCH 2/2] add tests as per reviews --- ext/opcache/tests/opt/sccp_array_key_exists.phpt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ext/opcache/tests/opt/sccp_array_key_exists.phpt b/ext/opcache/tests/opt/sccp_array_key_exists.phpt index b2c03419350f..af45088d8da8 100644 --- a/ext/opcache/tests/opt/sccp_array_key_exists.phpt +++ b/ext/opcache/tests/opt/sccp_array_key_exists.phpt @@ -1,5 +1,5 @@ --TEST-- -SCCP: Evaluate array_key_exists with boolean and integral float keys +SCCP: Evaluate array_key_exists with boolean and integral float keys, but not NAN or null --INI-- opcache.enable=1 opcache.enable_cli=1 @@ -16,6 +16,8 @@ function test() { 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]), ); } ?> @@ -27,13 +29,17 @@ $_main: 0000 RETURN int(1) test: - ; (lines=7, args=0, vars=0, tmps=0) + ; (lines=11, args=0, vars=0, tmps=1) ; (after optimizer) ; %s:%d-%d -0000 INIT_FCALL 4 %d string("var_dump") +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 DO_ICALL -0006 RETURN null +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