@phpstan-impure| Analyzer | Version | Result | Diagnostics |
|---|---|---|---|
| phan | 6.0.7Phan 6.0.7 php-ast version 1.1.3 PHP version used to run Phan: 8.5.9 | 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.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Enforced reported Lv.8+ | phpdoc_advanced_vendor_prefixed_impure_phpstan.php:35: Parameter #1 $string of function strlen expects string, string|null given. [identifier=argument.type] [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. [identifier=argument.type]
|
| psalm | 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac next: 7.0.0-beta19 |
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.46.0mago 1.46.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.70.1mir 0.70.1 | Recognized (no probes) | No diagnostics reported.
|
| phpantom | 0.9.0phpantom_lsp 0.9.0 | Recognized (no probes) | No diagnostics reported.
|
| 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]
|
| phpy | 0.2.0phpy 0.2.0 | Recognized (no probes) | No diagnostics reported.
|
| qodana | 262.8665.325Qodana 262.8665.325 | 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.5steins 0.1.5 (2026-08-12 revision 39b4cc1) | Recognized (no probes) | No diagnostics reported.
|
| phpstan-strict | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Enforced | phpdoc_advanced_vendor_prefixed_impure_phpstan.php:35: Parameter #1 $string of function strlen expects string, string|null given. [identifier=argument.type]
|
| psalm-next | 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 | 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]
}
}