Category
stdlib
Problem
Zend coerces null string operands to "" for internal string-compare builtins (strcmp, strncmp, etc.) and returns an integer compare result. This compiler’s VM raises TypeError on null, changing observable behavior for legacy code and php-src-strict parity.
Distinct from #4346 (array/object operands must TypeError) and #8825 (enum case operands must TypeError).
php-src reference
Repro
<?php
echo strcmp(null, 'a'), "\n";
echo strncmp(null, 'a', 1), "\n";
echo strcmp('a', null), "\n";
Committed: test/repro/maintainer_gap_strcmp_null_coerce.php
./script/docker-exec.sh -- bash -lc '
source script/php-env.sh
php test/repro/maintainer_gap_strcmp_null_coerce.php
php bin/vm.php test/repro/maintainer_gap_strcmp_null_coerce.php
'
| Call |
Zend PHP 8.2 |
This compiler VM |
strcmp(null, 'a') |
-1 |
TypeError |
strncmp(null, 'a', 1) |
-1 |
TypeError |
strcmp('a', null) |
1 |
(fatal on first null arg in script) |
Scope (PHP-in-PHP)
| Layer |
Path |
| VM |
ext/standard/strcmp.php, strncmp.php, shared VmString::coerceStringBuiltinArg guards |
| JIT/AOT |
matching lib/JIT/Builtin/ handlers |
| Tests |
test/compliance/cases/stdlib/strcmp_null_coerce.phpt |
Done when (php-src-strict)
Category
stdlibProblem
Zend coerces
nullstring operands to""for internal string-compare builtins (strcmp,strncmp, etc.) and returns an integer compare result. This compiler’s VM raisesTypeErroronnull, changing observable behavior for legacy code and php-src-strict parity.Distinct from #4346 (array/object operands must TypeError) and #8825 (enum case operands must TypeError).
php-src reference
ext/standard/string.c—PHP_FUNCTION(strcmp),PHP_FUNCTION(strncmp)(ZPP coerces null to empty string)Repro
Committed:
test/repro/maintainer_gap_strcmp_null_coerce.phpstrcmp(null, 'a')-1TypeErrorstrncmp(null, 'a', 1)-1TypeErrorstrcmp('a', null)1Scope (PHP-in-PHP)
ext/standard/strcmp.php,strncmp.php, sharedVmString::coerceStringBuiltinArgguardslib/JIT/Builtin/handlerstest/compliance/cases/stdlib/strcmp_null_coerce.phptDone when (php-src-strict)
nulloperands coerce to""and return Zend compare integers (noTypeError).