Repository navigation
Runtime: object array offset — isset()/array_key_exists() must TypeError (Illegal offset type) #6500
Copy link
Copy link
Closed
Labels
area:vmVirtual machineVirtual machineenhancementNew feature or requestNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimSpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language featuresPhase 2 – language features
Description
Category
language | runtime
Problem
Using a plain object as an array lookup key must throw TypeError: Illegal offset type. This compiler emits an internal Unknown index type 5 (or similar) from hash-table helpers instead of a catchable Zend-compatible TypeError.
Distinct from #5853 (enum case write offsets) and #5755 (enum case lookup in builtins) — this is the general illegal offset type guard for arbitrary objects on read/exists paths.
php-src reference
- php/php-src
Zend/zend_hash.c—_zend_hash_index_find, illegal offset checks - php/php-src
ext/standard/array.c—array_key_exists()→zend_hash_index_exists
Repro
<?php
class K {}
$a = [];
$a[new K] = 1; // may also need guard on write (separate from enum #5853)
try {
var_export(array_key_exists(new K, $a));
} catch (Throwable $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}
try {
var_export(isset($a[new K]));
} catch (Throwable $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "
class K {} \$a=[]; \$a[new K]=1;
try { array_key_exists(new K, \$a); } catch (Throwable \$e) { echo get_class(\$e), \": \", \$e->getMessage(); }
" 2>&1
'| Check | Zend PHP 8.x | bin/vm.php |
|---|---|---|
array_key_exists(new K, $a) |
TypeError: Illegal offset type |
Unknown index type 5 ❌ |
isset($a[new K]) |
TypeError: Illegal offset type |
Unknown index type 5 ❌ |
php-src-strict
- Enum case operands follow Stdlib: array_key_exists()/isset() with enum case lookup key must TypeError (zend_hash.c, ext/standard/array.c) #5755 / Language: enum case as array offset must TypeError (Illegal offset type) (zend_hash.c) #5853 — this issue covers non-enum objects and aligns error class/message with Zend.
Scope
| Path | Work |
|---|---|
lib/VM/HashTable.php (or offset helpers) |
Reject object keys with TypeError message matching Zend |
ext/standard/array_key_exists.php / isset lowering |
Ensure guard before hash probe |
lib/JIT/ |
Mirror guard in lowered isset / array_key_exists when in scope |
| Tests | test/compliance/cases/language/illegal_offset_object.phpt |
Done when
-
array_key_exists($obj, $arr),isset($arr[$obj]), andkey_exists($obj, $arr)throwTypeError: Illegal offset type - Repro passes under
php bin/vm.phpinsidescript/docker-exec.sh -
./script/ci-fast.sh --filter illegal_offset_objectgreen - No regression on int/string key paths
Related
- Language: enum case as array offset must TypeError (Illegal offset type) (zend_hash.c) #5853 · Stdlib: array_key_exists()/isset() with enum case lookup key must TypeError (zend_hash.c, ext/standard/array.c) #5755 · Stdlib: array_combine() with enum case keys — Error not backed int keys (ext/standard/array.c) #5538 · Epic: Self-host critical path — compiler compiles itself (M3→M5) #1492
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area:vmVirtual machineVirtual machineenhancementNew feature or requestNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimSpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language featuresPhase 2 – language features
Activity
PurHur commentedon Jun 6, 2026
claim: worker-lane-c — starting this run
Fix object array offset TypeError for isset/array_key_exists (#6500) (#…
PurHur commentedon Jun 6, 2026
Merged via #6508.
Verification:
array_key_exists(new K, $a),isset($a[new K]),key_exists(new K, $a)all throwTypeError: Illegal offset type(isset uses Illegal offset type in isset or empty).vendor/bin/phpunit --filter illegal_offset_object test/compliance/VMTest.php— OK (1 test)enum_illegal_array_offsetcompliance cases.Implementation: Extended
EnumCaseSupport::rejectIllegalArrayOffset()for plain objects/arrays; alignedarray_key_existsVM+JIT and JIT isset hashtable paths.