@phpstan-var@var, here on a property with no native type. Reading
it is what gives the property a type at all, so a tool that ignores the
prefix sees an untyped property rather than a wrongly typed one.
References:
- PHPStan phpdocs-basics: prefixed @phpstan-var
- Psalm supported_annotations.md: @psalm-var| 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 | Incidental (0/1) ⚠ 1 false positive | phpdoc_advanced_vendor_prefixed_var_phpstan.php:32: Argument 1 ($value) is new Holder()->value of type int but \Conformance\Tests\PhpdocAdvancedVendorPrefixedVarPhpStan\takesString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_vendor_prefixed_var_phpstan.php:27 [PhanTypeMismatchArgument]
Expectation diffLine 32: Unexpected errors ["Argument 1 ($value) is new Holder()->value of type int but \\Conformance\\Tests\\PhpdocAdvancedVendorPrefixedVarPhpStan\\takesString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_vendor_prefixed_var_phpstan.php:27 [PhanTypeMismatchArgument]"] |
| phpstan | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Incidental (0/1) reported Lv.5+ | phpdoc_advanced_vendor_prefixed_var_phpstan.php:32: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedVendorPrefixedVarPhpStan\takesString expects string, int given. [identifier=argument.type] [reported-from-level=5] With strict-rulesphpdoc_advanced_vendor_prefixed_var_phpstan.php:32: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedVendorPrefixedVarPhpStan\takesString expects string, int given. [identifier=argument.type]
Expectation diffLine 32: Unexpected errors ["Parameter #1 $value of function Conformance\\Tests\\PhpdocAdvancedVendorPrefixedVarPhpStan\\takesString expects string, int given. [identifier=argument.type] [reported-from-level=5]"] |
| psalm | 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac next: 7.0.0-beta19 |
Not enforced | phpdoc_advanced_vendor_prefixed_var_phpstan.php:32: Argument 1 of Conformance\Tests\PhpdocAdvancedVendorPrefixedVarPhpStan\takesString expects string, but int provided [InvalidScalarArgument]
Expectation diffLine 32: Unexpected errors ["Argument 1 of Conformance\\Tests\\PhpdocAdvancedVendorPrefixedVarPhpStan\\takesString expects string, but int provided [InvalidScalarArgument]"] |
| mago | 1.46.0mago 1.46.0 | Incidental (0/1) ⚠ 1 false positive | phpdoc_advanced_vendor_prefixed_var_phpstan.php:32: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedVendorPrefixedVarPhpStan\takesString`: expected `string`, but found `int`. [invalid-argument]
Expectation diffLine 32: Unexpected errors ["Invalid argument type for argument #1 of `Conformance\\Tests\\PhpdocAdvancedVendorPrefixedVarPhpStan\\takesString`: expected `string`, but found `int`. [invalid-argument]"] |
| mir | 0.70.1mir 0.70.1 | Incidental (0/1) ⚠ 1 false positive | phpdoc_advanced_vendor_prefixed_var_phpstan.php:32: InvalidArgument: Argument $value of takesString() expects 'string', got 'int' [MIR0201]
Expectation diffLine 32: Unexpected errors ["InvalidArgument: Argument $value of takesString() expects 'string', got 'int' [MIR0201]"] |
| phpantom | 0.9.0phpantom_lsp 0.9.0 | Incidental (0/1) ⚠ 1 false positive | phpdoc_advanced_vendor_prefixed_var_phpstan.php:32: Argument 1 ($value) expects string, got int [type_mismatch_argument]
Expectation diffLine 32: Unexpected errors ["Argument 1 ($value) expects string, got int [type_mismatch_argument]"] |
| intelephense | 1.18.5intelephense 1.18.5 | Incidental (0/1) ⚠ 1 false positive | phpdoc_advanced_vendor_prefixed_var_phpstan.php:32: Expected type 'string'. Found 'int'. [P1006]
Expectation diffLine 32: Unexpected errors ["Expected type 'string'. Found 'int'. [P1006]"] |
| phpy | 0.2.0phpy 0.2.0 | Not enforced ⚠ 1 false positive | phpdoc_advanced_vendor_prefixed_var_phpstan.php:32: Argument '1' passed to Conformance\Tests\PhpdocAdvancedVendorPrefixedVarPhpStan\takesString() is expected to be of type string, int given
Expectation diffLine 32: Unexpected errors ["Argument '1' passed to Conformance\\Tests\\PhpdocAdvancedVendorPrefixedVarPhpStan\\takesString() is expected to be of type string, int given"] |
| qodana | 262.8665.325Qodana 262.8665.325 | Incidental (0/1) ⚠ 1 false positive | phpdoc_advanced_vendor_prefixed_var_phpstan.php:32: Parameter '(new Holder())->value' type is not compatible with declaration when using strict type matching [PhpParamsInspection] phpdoc_advanced_vendor_prefixed_var_phpstan.php:32: Parameter '(new Holder())->value' type is not compatible with declaration [PhpStrictTypeCheckingInspection]
Expectation diffLine 32: Unexpected errors ["Parameter '(new Holder())->value' type is not compatible with declaration when using strict type matching [PhpParamsInspection]","Parameter '(new Holder())->value' type is not compatible with declaration [PhpStrictTypeCheckingInspection]"] |
| noverify | 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 | Not enforced ⚠ 1 false positive | phpdoc_advanced_vendor_prefixed_var_phpstan.php:32: potentially not safe accessing property 'value' [notSafeCall]
Expectation diffLine 32: Unexpected errors ["potentially not safe accessing property 'value' [notSafeCall]"] |
| steins | 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) | Not enforced | No diagnostics reported.
|
| phpstan-strict | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Incidental (0/1) ⚠ 1 false positive | phpdoc_advanced_vendor_prefixed_var_phpstan.php:32: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedVendorPrefixedVarPhpStan\takesString expects string, int given. [identifier=argument.type]
Expectation diffLine 32: Unexpected errors ["Parameter #1 $value of function Conformance\\Tests\\PhpdocAdvancedVendorPrefixedVarPhpStan\\takesString expects string, int given. [identifier=argument.type]"] |
| psalm-next | 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 | Not enforced ⚠ 1 false positive | phpdoc_advanced_vendor_prefixed_var_phpstan.php:32: Argument 1 of Conformance\Tests\PhpdocAdvancedVendorPrefixedVarPhpStan\takesString expects string, but int provided [InvalidScalarArgument]
Expectation diffLine 32: Unexpected errors ["Argument 1 of Conformance\\Tests\\PhpdocAdvancedVendorPrefixedVarPhpStan\\takesString expects string, but int provided [InvalidScalarArgument]"] |
<?php
declare(strict_types=1);
namespace Conformance\Tests\PhpdocAdvancedVendorPrefixedVarPhpStan;
/**
* Cross-tool handling of `@phpstan-var`
*
* The prefixed form of `@var`, here on a property with no native type. Reading
* it is what gives the property a type at all, so a tool that ignores the
* prefix sees an untyped property rather than a wrongly typed one.
*
* References:
* - PHPStan phpdocs-basics: prefixed @phpstan-var
* - Psalm supported_annotations.md: @psalm-var
*/
final class Holder
{
/**
* @phpstan-var int
*/
public $value = 1; // T: @phpstan-var
}
function takesInt(int $value): void
{
}
function takesString(string $value): void
{
}
takesInt((new Holder())->value); // V
// The prefixed tag says the property is an int, which is not a string.
takesString((new Holder())->value); // E?: @phpstan-var int should be enforced where the property is read