Category
stdlib · php-src-strict
Problem
PHP 8 internal functions with string parameter types reject null with TypeError, even when the caller file does not use declare(strict_types=1). This compiler coerces null to '' via VmString::coerceStringBuiltinArg() for many builtins, returning empty output instead of throwing.
| Repro |
Zend 8.2 (2026-07-12) |
VM (2026-07-12) |
urlencode(null) |
TypeError: ... must be of type string, null given |
'' |
rawurlencode(null) |
TypeError |
'' |
htmlspecialchars(null) |
TypeError |
'' |
htmlentities(null) |
TypeError |
'' |
strtolower(null) |
TypeError |
'' |
addcslashes(null, 'a') |
TypeError |
'' |
trim(null) |
TypeError |
TypeError ✓ |
strip_tags(null) |
TypeError |
TypeError ✓ |
Note: #4310 tracks scalar (int/bool) coercion for htmlspecialchars()/htmlentities(); #8730 / #8846 track enum-case operands. This issue is null only on typed $string parameters.
php-src reference
PHP implementation target
ext/standard/VmString.php — coerceStringBuiltinArg() callers: use InternalStrictArg::rejectNullString() (or equivalent) before coercion for typed internal params
lib/VM/InternalStrictArg.php — comment at line ~156 incorrectly suggests null→"" for all internals; align with Zend typed-param rules
- Per-builtin VM handlers in
ext/standard/*.php + JIT JitStringBuiltinArg paths
Repro
./script/docker-exec.sh -- bash -lc 'php test/repro/string_builtin_null.php'
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/string_builtin_null.php'
./script/docker-exec.sh -- bash -lc 'php test/repro/urlencode_null.php'
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/urlencode_null.php'
Done when
Category
stdlib· php-src-strictProblem
PHP 8 internal functions with
stringparameter types rejectnullwith TypeError, even when the caller file does not usedeclare(strict_types=1). This compiler coercesnullto''viaVmString::coerceStringBuiltinArg()for many builtins, returning empty output instead of throwing.urlencode(null)TypeError: ... must be of type string, null given''rawurlencode(null)TypeError''htmlspecialchars(null)TypeError''htmlentities(null)TypeError''strtolower(null)TypeError''addcslashes(null, 'a')TypeError''trim(null)TypeErrorTypeError✓strip_tags(null)TypeErrorTypeError✓Note: #4310 tracks scalar (int/bool) coercion for
htmlspecialchars()/htmlentities(); #8730 / #8846 track enum-case operands. This issue isnullonly on typed$stringparameters.php-src reference
ext/standard/url.c—PHP_FUNCTION(urlencode),PHP_FUNCTION(rawurlencode)ext/standard/html.c—PHP_FUNCTION(htmlspecialchars)ext/standard/string.c—PHP_FUNCTION(strtolower),PHP_FUNCTION(addcslashes)Zend/zend_API.h— typed params reject null unless explicitly nullablePHP implementation target
ext/standard/VmString.php—coerceStringBuiltinArg()callers: useInternalStrictArg::rejectNullString()(or equivalent) before coercion for typed internal paramslib/VM/InternalStrictArg.php— comment at line ~156 incorrectly suggests null→""for all internals; align with Zend typed-param rulesext/standard/*.php+ JITJitStringBuiltinArgpathsRepro
Done when
TypeErrorfornull$stringon VM (non-strict caller).phptguards undertest/compliance/cases/stdlib/string_builtin_null.phpt