Error Identifier: varTag.multipleTags
Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
function doFoo(): void
{
/**
* @var int
* @var string
*/
$test = someFunction();
}
Why is it reported? #
Multiple @var PHPDoc tags are placed above a single variable assignment. When a single variable is being assigned, PHPStan expects at most one @var tag (optionally with @phpstan-var or @psalm-var prefixed variants). Having multiple conflicting @var tags is ambiguous and PHPStan cannot determine which one should apply.
How to fix it #
Use a single @var tag with the correct type:
<?php declare(strict_types = 1);
function doFoo(): void
{
- /**
- * @var int
- * @var string
- */
+ /** @var int|string */
$test = someFunction();
}
If you need a more specific type than what PHPStan infers, use @phpstan-var alongside @var:
<?php declare(strict_types = 1);
function doFoo(): void
{
- /**
- * @var int
- * @var string
- */
+ /**
+ * @var int|string
+ * @phpstan-var positive-int|non-empty-string
+ */
$test = someFunction();
}
How to ignore this error #
You can use the identifier varTag.multipleTags to ignore this error using a comment:
// @phpstan-ignore varTag.multipleTags
codeThatProducesTheError();
You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:
parameters:
ignoreErrors:
-
identifier: varTag.multipleTags
Rules that report this error #
- PHPStan\Rules\PhpDoc\WrongVariableNameInVarTagRule [1]