Skip to content

Language: foreach(enum case) omits name/value props — Zend yields name (+ value if backed) (Zend/zend_enum.c) #23433

Description

@PurHur

Category

bug · php-src-strict · language / enums

Problem

Zend treats enum cases as objects with public properties name (unit + backed) and value (backed only). foreach ($case as $k => $v) yields those properties. The VM yields nothing.

Repro Zend 8.2 (2026-07-26) VM (2026-07-26)
unit foreach (E::A as ...) name='A' (empty)
backed foreach (S::A as ...) name='A',value='x' (empty)

php-src reference

PHP implementation target

  • Enum case property table / foreach path in lib/VM/ (enum support) — expose name and (for backed) value as public iterable props
  • Keep get_object_vars($case) / property read parity with foreach
  • No new C

Repro

./script/docker-exec.sh -- bash -lc 'cat >/tmp/repro_enum_foreach.php <<'"'"'PHP'"'"'
<?php
enum E { case A; }
$ks = [];
foreach (E::A as $k => $v) { $ks[] = "$k=" . var_export($v, true); }
echo implode(",", $ks), "\n";
enum S: string { case A = "x"; }
$ks = [];
foreach (S::A as $k => $v) { $ks[] = "$k=" . var_export($v, true); }
echo implode(",", $ks), "\n";
PHP
php /tmp/repro_enum_foreach.php
php bin/vm.php /tmp/repro_enum_foreach.php'

Done when

  • Unit and backed enum case foreach match Zend property names/values
  • Compliance .phpt under test/compliance/cases/language/
  • php-src-strict

Activity

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 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