Category
stdlib
Problem
utf8_encode() and utf8_decode() reject non-string operands with LogicException instead of coercing scalars like Zend.
php-src reference
Repro
Maintainer script: test/repro-maintainer/utf8_encode_scalar.php
HARNESS_DOCKER_RUN_OPTS='--memory=8g --cpus=2' ./script/docker-exec.sh -- bash -lc '
source script/php-env.sh
php test/repro-maintainer/utf8_encode_scalar.php
php bin/vm.php test/repro-maintainer/utf8_encode_scalar.php
'
| Mode |
utf8_encode(65) / utf8_decode(195) |
| Zend |
string(2) "65" / string(3) "195" |
| VM |
LogicException — only supports strings |
Scope
| Area |
Files |
| VM |
ext/standard/utf8_encode.php, ext/standard/utf8_decode.php |
| Helpers |
VmReflection::stringArg() or shared scalar coercion (see #4310 htmlspecialchars) |
| JIT |
JitUtf8Latin1 — already uses jitString(); align VM |
Done when
Verification
- Add
test/compliance/cases/stdlib/utf8_encode_decode_scalar.phpt
- VM + JIT filter; AOT if lowering exists
Category
stdlibProblem
utf8_encode()andutf8_decode()reject non-string operands withLogicExceptioninstead of coercing scalars like Zend.php-src reference
ext/standard/basic_functions.c—PHP_FUNCTION(utf8_encode),PHP_FUNCTION(utf8_decode)(convert_to_stringon argument Php stdlib specs implementation #1)Repro
Maintainer script:
test/repro-maintainer/utf8_encode_scalar.phputf8_encode(65)/utf8_decode(195)string(2) "65"/string(3) "195"LogicException— only supports stringsScope
ext/standard/utf8_encode.php,ext/standard/utf8_decode.phpVmReflection::stringArg()or shared scalar coercion (see #4310htmlspecialchars)JitUtf8Latin1— already usesjitString(); align VMDone when
utf8_encode()/utf8_decode()coerce int/float/bool to string before ISO-8859-1 ↔ UTF-8 transformTypeErrorlike Zend, notLogicExceptiontest/compliance/cases/stdlib/utf8_encode_decode_scalar.phptpasses VM + JITVerification
test/compliance/cases/stdlib/utf8_encode_decode_scalar.phpt