Category
stdlib
Problem
strcmp(), strcasecmp(), strncmp(), and strncasecmp() are typed string in PHP 8+. Passing array or object operands must throw TypeError with Zend message shapes. This compiler’s VM paths either compare incorrectly (strcmp([], []) → 0) or return sentinel integers (strcasecmp([], 'x') → -1) instead of failing.
php-src reference
Repro (failure today)
<?php
declare(strict_types=1);
try {
strcmp([], 'x');
} catch (Throwable $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}
var_export(strcmp([], []));
echo "\n";
var_export(strcasecmp([], 'x'));
echo "\n";
HARNESS_DOCKER_RUN_OPTS='--memory=8g --cpus=2' ./script/docker-exec.sh -- bash -lc '
source script/php-env.sh
php repro.php
php bin/vm.php repro.php
'
| Call |
Zend PHP 8.x |
This compiler VM (today) |
strcmp([], 'x') |
TypeError |
TypeError (OK) |
strcmp([], []) |
TypeError |
0 |
strcasecmp([], 'x') |
TypeError |
-1 |
Scope (this repo)
| Module |
Path |
| VM |
ext/standard/strcmp.php, strcasecmp.php, strncmp.php, strncasecmp.php |
| JIT/AOT |
lib/JIT/Builtin/ counterparts |
| Tests |
compliance PHPT + test/unit/*Compare* |
Done when
- Non-string operands (array/object/resource where disallowed) raise
TypeError, never silent compare or LogicException.
- No false
0 / -1 results for invalid types.
Category
stdlibProblem
strcmp(),strcasecmp(),strncmp(), andstrncasecmp()are typedstringin PHP 8+. Passing array or object operands must throwTypeErrorwith Zend message shapes. This compiler’s VM paths either compare incorrectly (strcmp([], [])→0) or return sentinel integers (strcasecmp([], 'x')→-1) instead of failing.php-src reference
ext/standard/string.c—PHP_FUNCTION(strcmp)et al. (ZPP string args)TypeErrorvsLogicException)Repro (failure today)
strcmp([], 'x')TypeErrorTypeError(OK)strcmp([], [])TypeError0strcasecmp([], 'x')TypeError-1Scope (this repo)
ext/standard/strcmp.php,strcasecmp.php,strncmp.php,strncasecmp.phplib/JIT/Builtin/counterpartstest/unit/*Compare*Done when
TypeError, never silent compare orLogicException.0/-1results for invalid types.