Category
stdlib / runtime
Problem
Zend coerces scalar operands to string for many internal string functions via zend_parse_parameters / _convert_to_string(). This compiler is inconsistent:
| Call |
Zend PHP 8.x |
This compiler |
strlen(123) |
3 |
3 ✅ |
str_contains(123, '2') |
true |
LogicException ❌ |
strpos(123, '2') |
1 |
LogicException ❌ |
Strict string-only checks in ext/standard/str_contains.php and strpos.php diverge from php-src.
php-src reference
ext/standard/string.c — PHP_FUNCTION(str_contains), PHP_FUNCTION(strpos) parameter parsing with string coercion
Zend/zend_operators.c — _convert_to_string(), convert_to_string() on zvals
ext/standard/basic_functions.c — shared parse_str helpers
Repro (today)
<?php
var_export(str_contains(123, '2'));
echo "\n";
var_export(strpos(123, '2'));
echo "\n";
echo strlen(123), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./script/apply-patches.sh >/dev/null && php bin/vm.php repro.php'
php repro.php
Expected (Zend): true, 1, 3
This compiler: fatal on str_contains / strpos.
Scope (this repo)
| Module |
Path |
| VM helpers |
ext/standard/VmString.php — shared coerceToString() used by string builtins |
| Stdlib |
ext/standard/str_contains.php, strpos.php, audit siblings (stripos, str_starts_with, …) |
| JIT |
mirror coercion in lib/JIT/Builtin/Standard/ stubs or defer with matrix note |
| Tests |
test/compliance/cases/stdlib/string_coerce_numeric.phpt |
Done when
Links
Category
stdlib/runtimeProblem
Zend coerces scalar operands to string for many internal string functions via
zend_parse_parameters/_convert_to_string(). This compiler is inconsistent:strlen(123)33✅str_contains(123, '2')trueLogicException❌strpos(123, '2')1LogicException❌Strict string-only checks in
ext/standard/str_contains.phpandstrpos.phpdiverge from php-src.php-src reference
ext/standard/string.c—PHP_FUNCTION(str_contains),PHP_FUNCTION(strpos)parameter parsing with string coercionZend/zend_operators.c—_convert_to_string(),convert_to_string()on zvalsext/standard/basic_functions.c— sharedparse_strhelpersRepro (today)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./script/apply-patches.sh >/dev/null && php bin/vm.php repro.php' php repro.phpExpected (Zend):
true,1,3This compiler: fatal on
str_contains/strpos.Scope (this repo)
ext/standard/VmString.php— sharedcoerceToString()used by string builtinsext/standard/str_contains.php,strpos.php, audit siblings (stripos,str_starts_with, …)lib/JIT/Builtin/Standard/stubs or defer with matrix notetest/compliance/cases/stdlib/string_coerce_numeric.phptDone when
strcmpstrictness)./script/ci-fast.sh --filter StringCoercegreendocs/capabilities.mdnotes coercion behavior where non-obviousLinks
(string)object cast /__toString: Language: (string) object cast must invoke __toString (Zend zend_operators.c parity) #3421