Repository navigation
Stdlib: strcoll()/strxfrm() locale collation parity #4376
Copy link
Copy link
Labels
area:vmVirtual machineVirtual machineimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimSpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsPhase 4 – stdlib for web apps
Description
Category
stdlib
Status (expanded 2026-06-04 — implementation-ready)
Today: strcoll() and strxfrm() are not registered in ext/standard/Module.php (function_exists('strcoll') → false on VM). This is not a behavioral drift issue yet — the builtins are missing.
Problem
Zend implements locale-aware string collation via strcoll() and transformation via strxfrm(), honoring the active locale set by setlocale(LC_COLLATE, ...). PurHur/php-compiler must match Zend’s collation ordering and return types, including behavior under the default C locale.
This is a building block for locale-sensitive sorting behavior in userland and pairs with #3254 (setlocale()).
php-src reference
ext/standard/string.c—PHP_FUNCTION(strcoll),PHP_FUNCTION(strxfrm)ext/standard/locale.c— locale handling andsetlocale()plumbing
Repro (failure today)
test/compliance/cases/stdlib/strcoll_strxfrm_repro.php:
<?php
setlocale(LC_COLLATE, 'C');
var_dump(strcoll('a', 'b') < 0);
var_dump(strcoll('a', 'a') === 0);
var_dump(strcoll('b', 'a') > 0);
$out = strxfrm('hello');
var_dump(is_string($out));./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && cd /compiler && php bin/vm.php test/compliance/cases/stdlib/strcoll_strxfrm_repro.php'| Runtime | Result |
|---|---|
| Zend | three true, is_string true |
| VM (today) | Call to undefined function strcoll() |
Scope (this repo)
| Area | Path |
|---|---|
| New builtins | ext/standard/strcoll.php, ext/standard/strxfrm.php |
| Registration | ext/standard/Module.php |
| VM | delegate to libc strcoll(3) / strxfrm(3) via thin wrapper (no new runtime/*.c logic) |
| JIT/AOT | optional phase 2 — document VM-only in matrix if deferred |
| Tests | test/compliance/cases/stdlib/strcoll_*.phpt |
Done when
- Repro runs on VM without undefined-function fatal; output matches Zend in
php-compiler:22.04-dev - Invalid argument types throw Zend-like
TypeError(seeext/standard/string.c) -
script/capability-matrix.phplists both functions as VM yes - No permanent
internal_*shims
Related
- Stdlib: setlocale() / localeconv() — C locale query and set (ext/standard/locale.c parity) #3254 —
setlocale()/localeconv() - Stdlib: get_defined_vars() local symbol table parity #4377 —
get_defined_vars()(different scope)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area:vmVirtual machineVirtual machineimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimSpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsPhase 4 – stdlib for web apps
Activity
PurHur commentedon Jun 9, 2026
claim: PHP Compiler STD Lib — starting this run
Stdlib: implement strcoll()/strxfrm() locale collation (#4376) (#7743)
PurHur commentedon Jun 9, 2026
Merged via #7743.
Verification (green):
php bin/vm.php -r 'var_dump(strcoll("a","b")<0); echo strxfrm("hello"),"\n";'→bool(true)+hellovendor/bin/phpunit --filter strcoll_strxfrm→ VM + JIT compliance pass (5 tests)vendor/bin/phpunit --filter strcoll_enum→ enum TypeError passvendor/bin/phpunit test/unit/AotRegressionFixtureCatalogTest.php --filter strcoll_strxfrm→ AOT compile-only passphp bin/compile.php -l test/fixtures/aot/compile-only/strcoll_strxfrm.php→ exit 0Implementation:
VmLocaleCollate(libc FFIstrcoll/strxfrmwith strcmp/identity fallbacks);strcollJIT lowers to libc likestrcmp;strxfrmVM-only (JIT deferred). php-src ref:ext/standard/string.c.Add JIT/AOT lowering for strxfrm() via libc strxfrm(3) (#4376). (#7861)
PurHur commentedon Jun 10, 2026
Merged via #7861.
Verification (Docker):
./vendor/bin/phpunit --filter "strcoll_strxfrm|strxfrm"→ OK (8 tests)./vendor/bin/phpunit --filter "AotTest.*strxfrm"→ OK (1 test)php bin/compile.php -l test/fixtures/aot/compile-only/strcoll_strxfrm.php→ OKstrxfrm()now lowers to libcstrxfrm(3)two-pass sizing on JIT/AOT (php-srcext/standard/string.c); VM path unchanged viaVmLocaleCollate.Add setlocale()/localeconv() via libc FFI (#6133) (#8372)