From 8c8fc99c1985081517267ac6b652638c03407985 Mon Sep 17 00:00:00 2001 From: PurHur Date: Wed, 20 May 2026 20:57:34 +0000 Subject: [PATCH] Web: JIT isset() on $_GET/$_POST with dynamic string keys (#70) Lower non-literal superglobal keys to __hashtable__offsetIsSetStringKey at compile time so routers can use isset($_GET[$param]) under JIT. Add VM compliance and real PHPT coverage; AOT isset on superglobals still segfaults at link (pre-existing, tracked separately). Co-authored-by: Cursor --- lib/JIT/IssetHelper.php | 22 ++++++++++++++++++- .../cases/stdlib/isset_get_dynamic_key.phpt | 19 ++++++++++++++++ .../real/cases/web_isset_get_dynamic_key.phpt | 15 +++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 test/compliance/cases/stdlib/isset_get_dynamic_key.phpt create mode 100644 test/real/cases/web_isset_get_dynamic_key.phpt diff --git a/lib/JIT/IssetHelper.php b/lib/JIT/IssetHelper.php index 4925b7332f6..d65ca5e63be 100644 --- a/lib/JIT/IssetHelper.php +++ b/lib/JIT/IssetHelper.php @@ -165,8 +165,28 @@ private static function compileHashTableOffsetIsSet( return $context->getTypeFromString('int1')->constInt($known ? 1 : 0, false); } + $ht = $context->helper->loadValue($container); + if (Variable::TYPE_STRING === $dim->type) { + return $context->builder->call( + $context->lookupFunction('__hashtable__offsetIsSetStringKey'), + $ht, + $context->helper->loadValue($dim) + ); + } + if (Variable::TYPE_NATIVE_LONG === $dim->type) { + $index = $context->builder->truncOrBitCast( + $context->helper->loadValue($dim), + $context->getTypeFromString('size_t') + ); + + return $context->builder->call( + $context->lookupFunction('__hashtable__offsetIsSet'), + $ht, + $index + ); + } throw new \LogicException( - 'isset() on superglobals only supports a string literal key in this compiler build' + 'isset() on superglobals only supports string or integer keys in this compiler build' ); } diff --git a/test/compliance/cases/stdlib/isset_get_dynamic_key.phpt b/test/compliance/cases/stdlib/isset_get_dynamic_key.phpt new file mode 100644 index 00000000000..b518f0ecc34 --- /dev/null +++ b/test/compliance/cases/stdlib/isset_get_dynamic_key.phpt @@ -0,0 +1,19 @@ +--TEST-- +stdlib isset() on $_GET with non-literal string key (issue #70) +--ENV-- +QUERY_STRING=name=Ada +--FILE-- +