str_split() / mb_str_split() length must be positive-intstr_split($s, -1): tools that model the stub
reject a non-positive length. Return non-emptiness is not probed here —
a array receiver would accept empty and non-empty alike.
Source: vimeo/psalm#6324 (4.10.0).
References:
- psalm#6324| Analyzer | Version | Result | Diagnostics |
|---|---|---|---|
| phan | 6.0.11Phan 6.0.11 php-ast version 1.1.3 PHP version used to run Phan: 8.5.11 | Pass | native_types_str_split_length.php:27: Argument #2 of this call to \str_split is typically a literal or constant but isn't, but argument #1 (which is typically a variable) is a literal or constant. The arguments may be in the wrong order. [PhanParamSuspiciousOrder] |
| phpstan | 2.3.5PHPStan - PHP Static Analysis Tool 2.3.5 | Pass reported Lv.4+ | native_types_str_split_length.php:27: Parameter #2 $length of function str_split expects int<1, max>, -1 given. [reported-from-level=5] native_types_str_split_length.php:28: Parameter #2 $length of function str_split expects int<1, max>, 0 given. [reported-from-level=5] native_types_str_split_length.php:32: Call to function mb_str_split() on a separate line has no effect. [reported-from-level=4] native_types_str_split_length.php:32: Parameter #2 $length of function mb_str_split expects int<1, max>, -1 given. [reported-from-level=5] With strict-rulesnative_types_str_split_length.php:27: Parameter #2 $length of function str_split expects int<1, max>, -1 given. native_types_str_split_length.php:28: Parameter #2 $length of function str_split expects int<1, max>, 0 given. native_types_str_split_length.php:32: Call to function mb_str_split() on a separate line has no effect. native_types_str_split_length.php:32: Parameter #2 $length of function mb_str_split expects int<1, max>, -1 given. |
| psalm | 6.20.9Psalm 6.20.9@f67170ac3c3b931f5088681e21d6c8babc601c08 next: 7.0.4 |
Pass | native_types_str_split_length.php:27: Argument 2 of str_split expects int<1, max>, but -1 provided [InvalidArgument] native_types_str_split_length.php:28: Argument 2 of str_split expects int<1, max>, but 0 provided [InvalidArgument] native_types_str_split_length.php:32: Argument 2 of mb_str_split expects int<1, max>, but -1 provided [InvalidArgument] |
| mago | 1.59.0mago 1.59.0 | Pass | native_types_str_split_length.php:27: Invalid argument type for argument #2 of `str_split`: expected `positive-int`, but found `int(-1)`. [invalid-argument] native_types_str_split_length.php:27: Expression has no effect as a statement [unused-statement] native_types_str_split_length.php:28: Invalid argument type for argument #2 of `str_split`: expected `positive-int`, but found `int(0)`. [invalid-argument] native_types_str_split_length.php:28: Expression has no effect as a statement [unused-statement] native_types_str_split_length.php:32: Expression has no effect as a statement [unused-statement] |
| mir | 0.91.0mir 0.91.0 | Fail | native_types_str_split_length.php:31: MixedArgument: Argument $value of takesString() is mixed [MIR1200] Expectation diffLine 31: Expected valid value to be accepted, got ["MixedArgument: Argument $value of takesString() is mixed [MIR1200]"] |
| phpantom | 0.11.1phpantom_lsp 0.11.1 | Pass | No diagnostics reported. |
| intelephense | 1.18.5intelephense 1.18.5 | Pass | No diagnostics reported. |
| phpactor | 2026.10.07.0Phpactor 2026.10.07.0 | Pass | No diagnostics reported. |
| phpy | 1.0.19490phpy 1.0.19490 | Pass | No diagnostics reported. |
| qodana | 262.11879.104PhpStorm 262.11879.104 | Pass | No diagnostics reported. |
| noverify | 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 | Fail | native_types_str_split_length.php:25: potentially not safe array access in parameter value of function Conformance\Tests\NativeTypesStrSplitLength\takesString [notSafeCall] native_types_str_split_length.php:31: potentially not safe array access in parameter value of function Conformance\Tests\NativeTypesStrSplitLength\takesString [notSafeCall] Expectation diffLine 25: Expected valid value to be accepted, got ["potentially not safe array access in parameter value of function Conformance\\Tests\\NativeTypesStrSplitLength\\takesString [notSafeCall]"] Line 31: Expected valid value to be accepted, got ["potentially not safe array access in parameter value of function Conformance\\Tests\\NativeTypesStrSplitLength\\takesString [notSafeCall]"] |
| steins | 0.1.8steins 0.1.8 (2026-09-21 revision 76306a9) | Pass | No diagnostics reported. |
| phpstan-strict | 2.3.5PHPStan - PHP Static Analysis Tool 2.3.5 | Pass | native_types_str_split_length.php:27: Parameter #2 $length of function str_split expects int<1, max>, -1 given. native_types_str_split_length.php:28: Parameter #2 $length of function str_split expects int<1, max>, 0 given. native_types_str_split_length.php:32: Call to function mb_str_split() on a separate line has no effect. native_types_str_split_length.php:32: Parameter #2 $length of function mb_str_split expects int<1, max>, -1 given. |
| psalm-next | 7.0.4Psalm 7.0.4@fa5b1f6e665cb743838ffd865b8fc96207f9409f | Pass | native_types_str_split_length.php:27: Argument 2 of str_split expects int<1, max>, but -1 provided [InvalidArgument] native_types_str_split_length.php:28: Argument 2 of str_split expects int<1, max>, but 0 provided [InvalidArgument] native_types_str_split_length.php:32: Argument 2 of mb_str_split expects int<1, max>, but -1 provided [InvalidArgument] |
<?php
declare(strict_types=1);
namespace Conformance\Tests\NativeTypesStrSplitLength;
/**
* `str_split()` / `mb_str_split()` length must be `positive-int`.
*
* The interesting call is `str_split($s, -1)`: tools that model the stub
* reject a non-positive length. Return non-emptiness is not probed here —
* a `array` receiver would accept empty and non-empty alike.
*
* Source: vimeo/psalm#6324 (4.10.0).
*
* References:
* - https://github.com/vimeo/psalm/pull/6324
*/
function takesString(string $value): void
{
}
$parts = str_split('hello', 2);
takesString($parts[0]); // V
str_split('hello', -1); // E?: length must be positive-int
str_split('hello', 0); // E?: 0 is not a positive-int
$mb = mb_str_split('hello', 2);
takesString($mb[0]); // V
mb_str_split('hello', -1); // E?: length must be positive-int