Skip to content

Stdlib: compact() must preserve enum case values not backed scalars (ext/standard/array.c) #5563

Description

@PurHur

Category

stdlib

Problem

compact() builds an array from symbol-table variables. When a variable holds a backed enum case object, Zend keeps the enum case in the result array. This compiler coerces enum cases to their backing scalar (int/string), breaking identity and follow-on APIs (get_debug_type, instanceof, serialization).

php-src reference

Repro (verified 2026-06-04)

<?php
enum E: int { case A = 1; }
$a = E::A;
var_export(compact('a'));
echo "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && cd /compiler && php repro.php && php bin/vm.php repro.php'
Runtime Output
Zend array ( 'a' => \E::A, )
VM array ( 'a' => 1, )

Scope (this repo)

Area Path
VM ext/standard/compact.php or VmCompact helper — copy enum case objects verbatim
JIT/AOT lib/JIT/Builtin/ compact lowering (pairs #5493 php-in-php migration)
C shrink Completing #5493 should delete phpc_compact.c without reintroducing scalarization

Done when

  • Repro var_export(compact('a')) matches Zend for backed and unit enums
  • JIT/AOT compact path matches VM when enabled
  • Compliance test/compliance/cases/stdlib/compact_enum_case.phpt green
  • ./script/ci-fast.sh --filter compact_enum 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-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions