@phpstan-impure| Analyzer | Version | Result | Diagnostics |
|---|---|---|---|
| phan | 6.0.10Phan 6.0.10 php-ast version 1.1.3 PHP version used to run Phan: 8.5.11 | Recognized (no probes) | phpdoc_advanced_vendor_prefixed_impure_phpstan.php:35: Argument 1 ($string) is flip() of type ?string but \strlen() takes string (expected type to be non-nullable) [PhanTypeMismatchArgumentNullableInternal]
|
| phpstan | 2.3.1PHPStan - PHP Static Analysis Tool 2.3.1 | Enforced reported Lv.8+ | phpdoc_advanced_vendor_prefixed_impure_phpstan.php:35: Parameter #1 $string of function strlen expects string, string|null given. [reported-from-level=8] With strict-rulesphpdoc_advanced_vendor_prefixed_impure_phpstan.php:35: Parameter #1 $string of function strlen expects string, string|null given.
|
| psalm | 6.20.0Psalm 6.20.0@804f03c0c183d149fcd4b8c7c0c9b3fbf836d34c next: 7.0.0-rc2 |
Recognized (no probes) | phpdoc_advanced_vendor_prefixed_impure_phpstan.php:35: Argument 1 of strlen cannot be null, possibly null value provided [PossiblyNullArgument]
|
| mago | 1.57.0mago 1.57.0 | Recognized (no probes) | phpdoc_advanced_vendor_prefixed_impure_phpstan.php:35: Argument #1 of function `strlen` is possibly `null`, but parameter type `string` does not accept it. [possibly-null-argument]
|
| mir | 0.87.0mir 0.87.0 | Recognized (no probes) | phpdoc_advanced_vendor_prefixed_impure_phpstan.php:35: PossiblyNullArgument: Argument $string of strlen() might be null [MIR0104]
|
| phpantom | 0.11.1phpantom_lsp 0.11.1 | Recognized (no probes) | phpdoc_advanced_vendor_prefixed_impure_phpstan.php:35: Argument 1 ($string) expects string, got ?string [type_mismatch_argument]
|
| intelephense | 1.18.5intelephense 1.18.5 | Recognized (no probes) | phpdoc_advanced_vendor_prefixed_impure_phpstan.php:35: Expected type 'string'. Found 'null|string'. [P1006]
|
| phpactor | 2026.10.07.0Phpactor 2026.10.07.0 | Recognized (no probes) | No diagnostics reported.
|
| phpy | 1.0.19409phpy 1.0.19409 | Recognized (no probes) | No diagnostics reported.
|
| qodana | 262.10968.76PhpStorm 262.10968.76 | Recognized (no probes) | 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 | Recognized (no probes) | No diagnostics reported.
|
| steins | 0.1.8steins 0.1.8 (2026-09-21 revision 76306a9) | Recognized (no probes) | No diagnostics reported.
|
| phpstan-strict | 2.3.1PHPStan - PHP Static Analysis Tool 2.3.1 | Enforced | phpdoc_advanced_vendor_prefixed_impure_phpstan.php:35: Parameter #1 $string of function strlen expects string, string|null given.
|
| psalm-next | 7.0.0-rc2Psalm 7.0.0-rc2@20339e3fe5b8d03bcd8061030eb2a83ad50e5783 | Recognized (no probes) | phpdoc_advanced_vendor_prefixed_impure_phpstan.php:35: Argument 1 of strlen cannot be null, possibly null value provided [PossiblyNullArgument]
|
<?php
declare(strict_types=1);
namespace Conformance\Tests\PhpdocAdvancedVendorPrefixedImpurePhpStan;
/**
* Cross-tool handling of `@phpstan-impure`.
*
* PHPStan remembers return values of non-void functions by default. The tag
* opts a function out of that memory so a second call can still be nullable
* after a successful null check on the first call.
*
* References:
* - PHPStan phpdocs-basics: Impure functions
* - PHPStan blog: Remembering and forgetting returned values
*/
/**
* @phpstan-impure
*/
function flip(): ?string // T: @phpstan-impure
{
return \rand(0, 1) === 1 ? 'heads' : null;
}
function demo(): void
{
if (flip() !== null) {
// Under @phpstan-impure the second call is still ?string, so strlen()
// rejects it. Only PHPStan memoizes return values by default, so this is
// the one tool the tag can be measured on: every other analyzer already
// treats a second call as ?string regardless of the tag, so its
// diagnostic here is baseline behaviour, not tag enforcement.
echo \strlen(flip()); // E?<phpstan> // E?<phpstan-strict> // E?[noise]
}
}