Repository navigation
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 featuresphase-4:stdlibPhase 4 – stdlib for web appsPhase 4 – stdlib for web appsstdlib
Description
Category
stdlib · php-src-strict · enum preservation
Problem
Zend rejects enum case array keys at array creation (TypeError: Illegal offset type). This compiler coerces enum cases to backing scalars when building arrays, so array_first() / array_last() silently return element values instead of failing:
enum E: string { case A = 'a'; }
$a = [E::A => 1]; // Zend: TypeError; VM: coerces key to "a"
array_first($a); // VM: int(1) — masks #9512 root cause at use siteRelated umbrella #9512 (literal keys) — this issue tracks first/last element builtins once illegal arrays exist or as guard when coercion remains.
php-src reference
- php/php-src
ext/standard/array.c—array_first,array_last - php/php-src
Zend/zend_hash.c— illegal offset type on enum keys
Repro
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "enum E: string { case A = \"a\"; } try { \$a = [E::A => 1]; array_first(\$a); } catch (Throwable \$e) { echo get_class(\$e), \"\\n\"; }"
php bin/vm.php -r "enum E: string { case A = \"a\"; } \$a = [E::A => 1]; var_dump(array_first(\$a));"
'| Step | Zend | VM today |
|---|---|---|
[E::A => 1] |
TypeError | coerced ["a"=>1] |
array_first($a) |
not reached | int(1) |
Scope (PHP-in-PHP)
| Path | Work |
|---|---|
ext/standard/VmArray.php |
valueFirst/valueLast — reject hashtables whose keys include illegal enum objects (or fix #9512 first) |
ext/standard/array_first.php, array_last.php |
surface TypeError at builtin boundary |
lib/JIT/Builtin/JitArrayElem.php |
share guards with VM |
Prefer fixing #9512 coercion first; keep this issue as compliance guard + PHPT.
Done when (php-src-strict)
-
[E::A => 1]throwsTypeError: Illegal offset typeon VM (ideal: Language: array literal enum case keys coerce to backing scalar — must TypeError (Zend/zend_hash.c) #9512) - If coercion temporarily remains,
array_first/array_lastthrow rather than return values for enum-keyed tables -
./script/ci-fast.sh --filter array_first_enum_keygreen
Related
- Language: array literal enum case keys coerce to backing scalar — must TypeError (Zend/zend_hash.c) #9512 literal enum keys · Stdlib: array_first()/array_last() — enum case elements materialize backing scalars (ext/standard/array.c) #8987 element scalarization · Stdlib: array_keys()/array_key_first()/array_key_last() on enum-case keyed arrays — TypeError Illegal offset type (ext/standard/array.c) #9871 array_key_first · Epic: Self-host critical path — compiler compiles itself (M3→M5) #1492
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 featuresphase-4:stdlibPhase 4 – stdlib for web appsPhase 4 – stdlib for web appsstdlib
Activity
PurHur commentedon Jul 4, 2026
claim: cursor-agent-lane-a — starting this run
PurHur commentedon Jul 4, 2026
claim released: repro green on master — both Zend and VM throw TypeError: Illegal offset type on [E::A => 1]; array_first not reached. Pivoting.
PurHur commentedon Jul 17, 2026
Cleanup bot: Closing as already green on master.
Prior worker note (2026-07-04): Zend and VM both throw
TypeError: Illegal offset typeon[E::A => 1]beforearray_first/array_lastrun. Claim was released; no open respin for this enum-key path (empty-array NULL remains #19183).