Skip to content

Language: (array) cast on backed enum case — must yield name/value array not backing list (Zend/zend_enum.c) #9659

Description

@PurHur

Category

language · php-src-strict

Problem

Casting a backed enum case to array must produce an associative array with name and value keys (case name + backing scalar). This compiler coerces the case to its backing scalar and wraps it in a list ([0 => backing]), which is wrong shape and wrong semantics.

php-src reference

Repro

test/repro/maintainer_gap_enum_array_cast.php:

<?php
enum E: int { case A = 1; case B = 2; }
var_export((array) E::A);
echo "\n";
var_export((array) E::B);
echo "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/maintainer_gap_enum_array_cast.php
php bin/vm.php test/repro/maintainer_gap_enum_array_cast.php
'
Engine (array) E::A
Zend PHP 8.2 array('name'=>'A','value'=>1)
VM today array(0=>1)

Scope (PHP-in-PHP)

Path Work
lib/VM/EnumCaseSupport.php (array) cast handler for enum-case zvals
lib/VM.php / cast opcodes Route CAST_ARRAY on enum cases
lib/Compiler.php Compile-time (array) on known enum case if optimized
JIT/AOT Shared cast helper

Done when (php-src-strict)

  • Repro var_export matches Zend for int- and string-backed enums
  • Pure (unit) enums: (array) on case → array('name'=>'CaseName') only
  • Compliance test/compliance/cases/language/enum_array_cast.phpt green

Related

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 machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language featuresstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions