Skip to content

Language: array-literal enum keys use typed TypeError (#28628) - #28735

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-28628-enum-array-literal-key-msg
Aug 7, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-28628-enum-array-literal-key-msg

Conversation

@PurHur

@PurHur PurHur commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fixes array-literal enum/object keys still throwing legacy Illegal offset type under PHP_COMPILER_PROFILE=8.4 while $a[$enum]=… already used Zend’s typed message (Closes #28628).
  • Root cause: INIT_ARRAY / ADD_ARRAY_ELEMENT threw a bare TypeError for TYPE_OBJECT/TYPE_ARRAY before EnumCaseSupport::rejectIllegalArrayOffset.
  • Reuse the shared zend_illegal_container_offset formatter for VM literals and JIT addElement / dim-write object keys (php-src-strict).

php-src reference

  • Zend/zend_hash.c — illegal key TypeError
  • Zend/zend.c — zend_illegal_container_offset()

PHP implementation

  • lib/VM.php — INIT_ARRAY / class-body defaults call rejectIllegalArrayOffset first
  • lib/VM/EnumCaseSupport.php — formatIllegalContainerOffsetMessage() shared helper
  • lib/JIT/HashTableHelper.php / HashTableWriteLlvm.php / Variable.php — typed JIT messages from compile-time enum class hints

Test plan

  • Issue repro:
    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    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
    '
    Output (both):
    unit: TypeError:Cannot access offset of type E on array
    unit-assign: TypeError:Cannot access offset of type E on array
    backed: TypeError:Cannot access offset of type S on array
    backed-assign: TypeError:Cannot access offset of type S on array
    
  • PHP_COMPILER_PROFILE=8.2 still emits Illegal offset type (legacy)
  • vendor/bin/phpunit --filter EnumCaseTypeNameTest — OK (5 tests)

Made with Cursor

INIT_ARRAY/ADD_ARRAY_ELEMENT threw bare "Illegal offset type" before
EnumCaseSupport::rejectIllegalArrayOffset; reuse the assignment-path
formatter (zend_illegal_container_offset) for VM and JIT literal keys.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant