Category
stdlib
Problem
htmlspecialchars() and htmlentities() require TYPE_STRING for argument #1 ($string). Zend coerces int/float/bool (and objects with __toString) via zend_parse_parameter / convert_to_string before escaping.
This compiler throws LogicException: ... only supports strings in this compiler build (ext/standard/htmlspecialchars.php, ext/standard/htmlentities.php).
Related: #4296 (closed) fixed null $encoding; this issue is argument #1 coercion only.
php-src reference
Repro (failure today)
<?php
echo htmlspecialchars(42), "\n";
echo htmlentities(true), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "echo htmlspecialchars(42), \"\\n\";"
php bin/vm.php -r "echo htmlspecialchars(42), \"\\n\";"
'
| Runtime |
Output |
| Zend PHP |
42 then 1 |
bin/vm.php |
LogicException: htmlspecialchars() only supports strings... |
double_encode bool coercion is separate (existing PHPT covers bool); align flags/encoding with #4130 when touching VmString::htmlspecialchars.
Scope
| Module |
Path |
| VM |
ext/standard/htmlspecialchars.php, htmlentities.php — use shared scalar→string helper (match nl2br() / preg_quote() parity issues) |
| Core |
ext/standard/VmString.php — htmlspecialchars() / htmlentities() entry |
| JIT |
JitStringArg / JitHtmlspecialchars — coerce non-string args like other string builtins |
| Tests |
test/compliance/cases/stdlib/htmlspecialchars_scalar_coerce.phpt |
Done when
Links
Category
stdlibProblem
htmlspecialchars()andhtmlentities()requireTYPE_STRINGfor argument #1 ($string). Zend coerces int/float/bool (and objects with__toString) viazend_parse_parameter/convert_to_stringbefore escaping.This compiler throws
LogicException: ... only supports strings in this compiler build(ext/standard/htmlspecialchars.php,ext/standard/htmlentities.php).Related: #4296 (closed) fixed null
$encoding; this issue is argument #1 coercion only.php-src reference
ext/standard/html.c—PHP_FUNCTION(htmlspecialchars),PHP_FUNCTION(htmlentities)Zend/zend_operators.c— scalarconvert_to_stringRepro (failure today)
42then1bin/vm.phpLogicException: htmlspecialchars() only supports strings...double_encodebool coercion is separate (existing PHPT covers bool); align flags/encoding with #4130 when touchingVmString::htmlspecialchars.Scope
ext/standard/htmlspecialchars.php,htmlentities.php— use shared scalar→string helper (matchnl2br()/preg_quote()parity issues)ext/standard/VmString.php—htmlspecialchars()/htmlentities()entryJitStringArg/JitHtmlspecialchars— coerce non-string args like other string builtinstest/compliance/cases/stdlib/htmlspecialchars_scalar_coerce.phptDone when
htmlspecialchars(42)andhtmlentities(true)match Zend on VMTypeErrorlike Zend, notLogicException./script/ci-fast.sh --filter htmlspecialchars_scalargreenLinks
__toStringduring coercion · Epic: Self-host critical path — compiler compiles itself (M3→M5) #1492