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
Related
Category
stdlibProblem
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
ext/standard/array.c—PHP_FUNCTION(compact)/php_compact_varZend/zend_enum.c— enum case zvals are objectsRepro (verified 2026-06-04)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && cd /compiler && php repro.php && php bin/vm.php repro.php'array ( 'a' => \E::A, )array ( 'a' => 1, )Scope (this repo)
ext/standard/compact.phporVmCompacthelper — copy enum case objects verbatimlib/JIT/Builtin/compact lowering (pairs #5493 php-in-php migration)phpc_compact.cwithout reintroducing scalarizationDone when
var_export(compact('a'))matches Zend for backed and unit enumstest/compliance/cases/stdlib/compact_enum_case.phptgreen./script/ci-fast.sh --filter compact_enumgreenRelated
phpc_compact.c, PHP implementationget_debug_type, Stdlib: get_class() on enum case must return enum name not false (ext/standard/basic_functions.c) #5484get_class