<?php
foreach ([[123, ','], [ 'a,b,c', 456 ]] as [$s, $tok]) {
try {
strtok($s, $tok);
} catch (Throwable $e) {
echo get_class($e), ': ', substr($e->getMessage(), 0, 60), "...\n";
}
}
<?php
$s = 'a,b,c';
echo strtok($s, ','), ' ', strtok(','), ' ', strtok(','), "\n";
// a b c
Category
stdlibProblem
#3201 (closed) registered
strtok()with continuation state (ext/standard/strtok.php,VmString::strtok). Invalid operand types still throwLogicExceptioninstead of ZendTypeError, and JIT must not segfault on bad types.Same pattern as #4551–#4581 string TypeError sweep.
php-src reference
ext/standard/string.c—PHP_FUNCTION(strtok)ext/standard/basic_functions.stub.php—(string $string, ?string $token = null)Repro
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php' php repro.phpTypeErrorfor argument #1 and #2 withmust be of type stringLogicException: strtok() argument #N must be a string in this compiler buildHappy path unchanged:
Scope (this repo)
ext/standard/strtok.php,ext/standard/VmString.phpext/standard/JitStrtok.php/StringStrtok— TypeError + no segfaulttest/compliance/cases/stdlib/strtok_type_error.phptDone when
a b cline./script/ci-fast.sh --filter strtok_typegreenRelated
str_shuffle()TypeError template