Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion lib/JIT/IssetHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
}

Expand Down
19 changes: 19 additions & 0 deletions test/compliance/cases/stdlib/isset_get_dynamic_key.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
stdlib isset() on $_GET with non-literal string key (issue #70)
--ENV--
QUERY_STRING=name=Ada
--FILE--
<?php
$key = 'name';
if (isset($_GET[$key])) {
echo $_GET[$key], "\n";
} else {
echo "missing\n";
}
$missing = 'absent';
if (!isset($_GET[$missing])) {
echo "absent ok\n";
}
--EXPECT--
Ada
absent ok
15 changes: 15 additions & 0 deletions test/real/cases/web_isset_get_dynamic_key.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Web: isset() on $_GET with non-literal string key (issue #70)
--ENV--
QUERY_STRING=name=World
--FILE--
<?php
$key = 'name';
if (isset($_GET[$key])) {
echo 'Hello ', $_GET[$key], "\n";
} else {
echo "Hello Guest\n";
}
--EXPECT--
Hello World