Skip to content

Language: (array) cast on enum cases — regression vs closed #5536 (zend_enum.c) #5771

Closed

Description

@PurHur

Category

language

Problem

(array) on backed or unit enum case values must produce Zend’s name / value hash shape (zend_enum_to_array()). #5536 was closed, but VM still coerces to a numeric list (array(0 => 1) / array(0 => 'A')).

lib/VM/CastSupport.php has enumCaseEntryToArray() / enumCaseObjectToArray(), but the cast opcode path likely receives a backing scalar or non-TYPE_ENUM_CASE zval before CastSupport::toArray() runs.

php-src reference

Repro

test/repro-maintainer/parity_enum_array_cast_backed.php:

<?php
enum E: int { case A = 1; }
var_export((array) E::A);

test/repro-maintainer/parity_enum_array_cast_unit.php:

<?php
enum U { case A; }
var_export((array) U::A);
docker info >/dev/null
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro-maintainer/parity_enum_array_cast_backed.php
php test/repro-maintainer/parity_enum_array_cast_unit.php
php test/repro-maintainer/parity_enum_array_cast_backed.php
php test/repro-maintainer/parity_enum_array_cast_unit.php'
Cast Zend PHP 8.2 VM (2026-06-04)
Backed E::A array('name'=>'A','value'=>1) array(0=>1)
Unit U::A array('name'=>'A') array(0=>'A')

Scope (PHP-in-PHP)

Path Work
lib/VM/CastSupport.php Ensure enum cases reach enumCase*ToArray()
lib/VM.php TYPE_CAST_ARRAY — do not pre-coerce enum operands to backing
lib/Compiler.php / JIT Phase 2: native (array) lowering if deferred
Tests test/compliance/cases/language/enum_array_cast_*.phpt (may exist from #5536 — re-enable)

Done when

  • Both repro scripts match Zend var_export on VM
  • ./script/ci-fast.sh --filter EnumArrayCast green
  • No new logic in runtime/*.c; fix stays in lib/VM/

Related

Activity

  1. added
    enhancementNew feature or request
    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 4, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-c — starting this run

  3. PurHur commented on Jun 4, 2026

    @PurHur
    OwnerAuthor

    verified fixed

  4. PurHur commented on Jun 4, 2026

    @PurHur
    OwnerAuthor

    Verified on master: repro scripts and EnumArrayCastTest pass in Docker (fixed by #5536/#5561). No additional VM change required.

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 features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions