Skip to content

Stdlib: array_first()/array_last() on enum-keyed arrays — must TypeError at access not return values (ext/standard/array.c) #10003

Closed

Description

@PurHur

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 site

Related umbrella #9512 (literal keys) — this issue tracks first/last element builtins once illegal arrays exist or as guard when coercion remains.

php-src reference

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)

Related

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 19, 2026
  2. PurHur commented on Jul 4, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-a — starting this run

  3. PurHur commented on Jul 4, 2026

    @PurHur
    OwnerAuthor

    claim released: repro green on master — both Zend and VM throw TypeError: Illegal offset type on [E::A => 1]; array_first not reached. Pivoting.

  4. PurHur commented on Jul 17, 2026

    @PurHur
    OwnerAuthor

    Cleanup bot: Closing as already green on master.

    Prior worker note (2026-07-04): Zend and VM both throw TypeError: Illegal offset type on [E::A => 1] before array_first/array_last run. Claim was released; no open respin for this enum-key path (empty-array NULL remains #19183).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language featuresphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions