Category
stdlib
Problem
Zend sort([E::B, E::A]) on backed enum cases sorts in place (by backing value) and leaves enum case objects in the array (A then B for A=1, B=2).
This compiler VM throws LogicException: sort() only supports homogeneous string or integer arrays in this compiler build — no sort happens.
Related: #5546 tracks coercion to scalars after sort; this issue is the earlier failure mode (hard reject vs Zend acceptance).
php-src reference
Repro
docker info >/dev/null
./script/docker-exec.sh -- bash -lc '
php -r "enum E: int { case A = 1; case B = 2; } \$a = [E::B, E::A]; sort(\$a); foreach (\$a as \$v) echo \$v->name, \"\\n\";"
php bin/vm.php -r "enum E: int { case A = 1; case B = 2; } \$a = [E::B, E::A]; sort(\$a); foreach (\$a as \$v) echo \$v->name, \"\\n\";"
'
Zend: A then B
VM: LogicException before loop
Scope (PHP-in-PHP)
| Layer |
Path |
| VM |
ext/standard/sort_.php, lib/VM/EnumCaseSupport.php — allow enum case arrays; compare via compareEnumCasesForMinMax |
| JIT |
lib/JIT/Builtin/ sort lowering when element type is enum case |
| Tests |
test/compliance/cases/stdlib/sort_enum_cases.phpt |
Done when
Category
stdlibProblem
Zend
sort([E::B, E::A])on backed enum cases sorts in place (by backing value) and leaves enum case objects in the array (AthenBforA=1,B=2).This compiler VM throws
LogicException: sort() only supports homogeneous string or integer arrays in this compiler build— no sort happens.Related: #5546 tracks coercion to scalars after sort; this issue is the earlier failure mode (hard reject vs Zend acceptance).
php-src reference
ext/standard/array.c—php_array_sort/ enum-aware comparisonsZend/zend_enum.cRepro
Zend:
AthenBVM: LogicException before loop
Scope (PHP-in-PHP)
ext/standard/sort_.php,lib/VM/EnumCaseSupport.php— allow enum case arrays; compare viacompareEnumCasesForMinMaxlib/JIT/Builtin/sort lowering when element type is enum casetest/compliance/cases/stdlib/sort_enum_cases.phptDone when
A/Bon VM without exception./script/ci-fast.sh --filter sort_enumgreen