Skip to content

Language: array-literal enum case keys TypeError still "Illegal offset type" — Zend "Cannot access offset of type E" (Zend/zend_hash.c) #28628

Closed

Description

@PurHur

Category

bug · php-src-strict · enum array keys · pillar 4

Problem

Assignment $a[$enum] = … already emits Zend’s typed message (Cannot access offset of type E on array). Array literals [E::A => 1] still throw the legacy Illegal offset type string under VM/JIT PROFILE=8.4.

Re-verified 2026-08-07 @ 823e740094 vs php:8.4-cli 8.4.24.

Repro Zend 8.4.24 VM/JIT PROFILE=8.4
$a=[]; $a[E::A]=1; (unit enum) Cannot access offset of type E on array same (OK)
$arr = [E::A => 1]; Cannot access offset of type E on array Illegal offset type
$arr = [S::A => 1]; (string-backed) Cannot access offset of type S on array Illegal offset type

Related history (#9512 / #16986) fixed acceptance of enum keys; this issue is message parity on the literal path only.

php-src reference

PHP implementation target

  • Array-literal key store in lib/ / VM init-array lowering — reuse the same TypeError formatter the assignment path already uses (Cannot access offset of type %s on array)
  • JIT must match — no new C

Repro

./script/docker-exec.sh -- bash -lc '
PHP_COMPILER_PROFILE=8.4 php bin/vm.php test/repro/maintainer_enum_array_literal_key_msg.php
PHP_COMPILER_PROFILE=8.4 php bin/jit.php test/repro/maintainer_enum_array_literal_key_msg.php
'
# Compare:
# docker run --rm -i php:8.4-cli php < test/repro/maintainer_enum_array_literal_key_msg.php

Done when

  • Array-literal unit-/backed-enum keys throw TypeError: Cannot access offset of type <Enum> on array (VM + JIT)
  • Assignment path remains unchanged / still Zend-shaped
  • Compliance or repro guard; php-src-strict; no php-compiler-strict shortcut

Activity

  1. added
    bugSomething isn't working
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Aug 7, 2026
  2. PurHur commented on Aug 7, 2026

    @PurHur
    OwnerAuthor

    Inline repro (if test/repro/maintainer_enum_array_literal_key_msg.php is not on the branch yet)

    <?php
    enum E { case A; }
    try {
      $arr = [E::A => 1];
      echo "accepted\n";
    } catch (Throwable $e) {
      echo get_class($e), ":", $e->getMessage(), "\n";
    }

    Expect Zend: TypeError:Cannot access offset of type E on array

  3. PurHur commented on Aug 7, 2026

    @PurHur
    OwnerAuthor

    claim: Worker lane C — starting this run

  4. PurHur commented on Aug 7, 2026

    @PurHur
    OwnerAuthor

    Merged — array-literal enum keys now throw Zend-shaped Cannot access offset of type <Enum> on array under PROFILE≥8.3 (same as assignment).

    Cause: INIT_ARRAY threw bare Illegal offset type for TYPE_OBJECT before rejectIllegalArrayOffset.
    Fix: reuse shared typed formatter; JIT literal/addElement path matches.

    Verification: issue repro VM+JIT typed messages; PROFILE=8.2 still legacy; EnumCaseTypeNameTest OK.

    PR: #28735

  5. PurHur commented on Aug 7, 2026

    @PurHur
    OwnerAuthor

    Closed via squash-merge of #28735.

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:compilerCompiler / CFG / JITarea:vmVirtual machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions