Skip to content

Stdlib: array_key_exists()/isset() with enum case lookup key must TypeError (zend_hash.c, ext/standard/array.c) #5755

Closed

Description

@PurHur

Category

stdlib + language

Problem

array_key_exists($key, $array) and isset($array[$key]) must throw TypeError: Illegal offset type when $key is an enum case object. The VM accepts enum cases and may match via backing coercion (array_key_exists(E::A, [1=>'v']) → true).

php-src reference

Repro

test/repro-maintainer/parity_array_key_exists_enum_key.php

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/parity_array_key_exists_enum_key.php
php bin/vm.php test/repro-maintainer/parity_array_key_exists_enum_key.php'
Site Zend VM today
array_key_exists(E::A, $a) TypeError bool(true)
isset($a[E::A]) TypeError bool(true)

Scope (PHP-in-PHP)

Path Work
ext/standard/ array_key_exists — reject enum case keys before hash lookup
lib/VM.php isset/dim read paths for enum keys
Tests compliance PHPT

Done when

  • Repro throws TypeError on VM for both calls
  • No silent backing match for enum lookup keys

Related

#5753 · #4135 · #1492

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 4, 2026
  2. PurHur commented on Jun 13, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 13, 2026

    @PurHur
    OwnerAuthor

    Unclaiming: array_key_exists()/isset() enum key TypeError already green on master. VM repro prints TypeError for both calls matching Zend. Recommend closing.

  4. PurHur commented on Jul 15, 2026

    @PurHur
    OwnerAuthor

    Closing: repro behavior already green on master (2026-07-15).

    Verification:

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    php -r "enum E: int { case A=1; } \$a=[1=>\"v\"];
    try { array_key_exists(E::A,\$a); } catch (TypeError \$e) { echo \"zend array_key_exists: TypeError\n\"; }
    try { isset(\$a[E::A]); } catch (TypeError \$e) { echo \"zend isset: TypeError\n\"; }"
    php bin/vm.php -r "enum E: int { case A=1; } \$a=[1=>\"v\"];
    try { array_key_exists(E::A,\$a); } catch (TypeError \$e) { echo \"vm array_key_exists: TypeError\n\"; }
    try { isset(\$a[E::A]); } catch (TypeError \$e) { echo \"vm isset: TypeError\n\"; }"'

    → both Zend and VM throw TypeError for enum-case lookup keys.

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-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions