Skip to content

Stdlib: compact() — enum case variables must stay objects not backing scalars (ext/standard/basic_functions.c) #8686

Description

@PurHur

Category

stdlib | php-src-strict

Problem

compact('x') when $x holds an enum case must return the enum case object in the result array. This compiler coerces backed enum cases to their backing scalar (1 instead of E::A).

Related coercion family: #5547 (array_values/array_merge), #5691 (sort), but compact() is not covered.

php-src reference

Repro (failure today)

<?php
enum E: int { case A = 1; }
$a = E::A;
var_export(compact('a'));
php bin/vm.php -r "enum E: int { case A = 1; } \$a = E::A; var_export(compact('a'));"
# VM:  array ('a' => 1)
php -r "enum E: int { case A = 1; } \$a = E::A; var_export(compact('a'));"
# Zend: array ('a' => \E::A)

Compliance guard (expects enum object — currently fails VM):

php bin/vm.php test/compliance/cases/stdlib/compact_enum_case.phpt

Scope (this repo)

Layer Path
VM ext/standard/VmScope.phpcompact() variable copy without enum scalarization
JIT ext/standard/compact_.php / JIT lowering if literal name list is compiled
Tests test/compliance/cases/stdlib/compact_enum_case.phpt (exists, red on VM)

Done when

  • Inline repro and compliance .phpt both show \E::A in result array
  • Unit enum cases preserved too (not just backed)
  • Missing variable name still omitted from result (unchanged Zend behavior)
  • VM + JIT agree when both in scope; PHP-in-PHP only

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