Category
stdlib · php-src-strict
Problem
array_rand() on an array of enum case objects must return a key whose element remains an enum object. VM indexes the array and materializes the backing scalar (int/string) instead of preserving the enum case.
Verified 2026-06-16: Zend PHP 8.2 vs php bin/vm.php.
php-src reference
Repro
test/repro/maintainer_gap_array_rand_enum.php
php test/repro/maintainer_gap_array_rand_enum.php
php bin/vm.php test/repro/maintainer_gap_array_rand_enum.php
|
Zend |
VM (wrong) |
get_debug_type($arr[array_rand($arr)]) |
E |
int |
$value instanceof E |
true |
false |
enum E: int { case A = 1; case B = 2; }
$arr = [E::A, E::B, E::A];
$key = array_rand($arr);
$value = $arr[$key]; // Zend: E::A|E::B; VM: 1|2
Scope (PHP-in-PHP)
| Path |
Work |
ext/standard/array_rand.php |
Stop enum→scalar coercion when returning elements / building result |
lib/VM/ArrayOps.php (if shared) |
Preserve enum objects in array access paths used by array_rand |
lib/JIT/Builtin/Standard/ArrayRand.php |
JIT parity when in scope |
| Tests |
test/compliance/cases/stdlib/array_rand_enum.phpt |
Done when
Related
#5554 array_slice/reverse · #5586 array_pop/splice · #1492
Category
stdlib· php-src-strictProblem
array_rand()on an array of enum case objects must return a key whose element remains an enum object. VM indexes the array and materializes the backing scalar (int/string) instead of preserving the enum case.Verified 2026-06-16: Zend PHP 8.2 vs
php bin/vm.php.php-src reference
ext/standard/array.c—php_array_randZend/zend_enum.c— enum object storage in arraysRepro
test/repro/maintainer_gap_array_rand_enum.phpget_debug_type($arr[array_rand($arr)])Eint$value instanceof EtruefalseScope (PHP-in-PHP)
ext/standard/array_rand.phplib/VM/ArrayOps.php(if shared)array_randlib/JIT/Builtin/Standard/ArrayRand.phptest/compliance/cases/stdlib/array_rand_enum.phptDone when
array_rand()on enum case arrays returns keys mapping to enum objects (same as Zend)array_rand($arr, $num)multi-pick parity when applicableRelated
#5554 array_slice/reverse · #5586 array_pop/splice · #1492