Category
stdlib · VM builtin args · php-src-strict
Sibling: #9278 (bitwise SORT_NATURAL|SORT_FLAG_CASE expressions on ksort/asort). This issue is the common case: passing a named sort constant (SORT_NUMERIC, SORT_STRING, …) as the flags argument to sort() / rsort().
Problem
sort($array, SORT_NUMERIC) throws LogicException: sort() flags must be an integer in this compiler build even though var_dump(SORT_NUMERIC) is int(1) and Zend sorts correctly.
VmInternalCompare::resolveFrameSortFlags() requires Variable::TYPE_INTEGER on the call argument slot; constants like SORT_NUMERIC are not materialized as integer-typed frame operands at the callsite (same class of bug as #9278, but hits sort_ / rsort_ and the most common stdlib sort flags).
php-src reference
ext/standard/array.c — php_array_sort() / php_sort() flag parsing
ext/standard/php_sort.h — SORT_REGULAR, SORT_NUMERIC, SORT_STRING, SORT_NATURAL, SORT_FLAG_CASE
Repro
php test/repro/maintainer_gap_sort_sort_numeric_constant.php # Zend: 1,2,10
php bin/vm.php test/repro/maintainer_gap_sort_sort_numeric_constant.php # LogicException
Also fails for rsort($a, SORT_NUMERIC); asort/ksort family may share resolveFrameSortFlags().
Done when (php-src-strict)
sort() / rsort() accept SORT_* named constants and literal int flags at runtime on VM.
SORT_NUMERIC sorts string elements numerically (['10','2','1'] → 1,2,10).
- JIT/AOT:
VmInternalCompare::resolveJitSortFlags() path stays aligned when in scope.
- Compliance
.phpt under test/compliance/cases/stdlib/.
Implementation hints
Category
stdlib· VM builtin args · php-src-strictSibling: #9278 (bitwise
SORT_NATURAL|SORT_FLAG_CASEexpressions on ksort/asort). This issue is the common case: passing a named sort constant (SORT_NUMERIC,SORT_STRING, …) as the flags argument tosort()/rsort().Problem
sort($array, SORT_NUMERIC)throwsLogicException: sort() flags must be an integer in this compiler buildeven thoughvar_dump(SORT_NUMERIC)isint(1)and Zend sorts correctly.VmInternalCompare::resolveFrameSortFlags()requiresVariable::TYPE_INTEGERon the call argument slot; constants likeSORT_NUMERICare not materialized as integer-typed frame operands at the callsite (same class of bug as #9278, but hitssort_/rsort_and the most common stdlib sort flags).php-src reference
ext/standard/array.c—php_array_sort()/php_sort()flag parsingext/standard/php_sort.h—SORT_REGULAR,SORT_NUMERIC,SORT_STRING,SORT_NATURAL,SORT_FLAG_CASERepro
Also fails for
rsort($a, SORT_NUMERIC);asort/ksortfamily may shareresolveFrameSortFlags().Done when (php-src-strict)
sort()/rsort()acceptSORT_*named constants and literal int flags at runtime on VM.SORT_NUMERICsorts string elements numerically (['10','2','1']→1,2,10).VmInternalCompare::resolveJitSortFlags()path stays aligned when in scope..phptundertest/compliance/cases/stdlib/.Implementation hints
ext/standard/sort_.php,ext/standard/VmInternalCompare.php::resolveFrameSortFlags()— coerce constant fetches / enum-backed int operands to integer type before the strictTYPE_INTEGERguard, or resolve viaconstantFetch()like the JIT path.resolveFrameSortFlags().