Menu

← Back to varTag.*

Error Identifier: varTag.variableNotFound

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 $foo */
	echo 'hello';
}

Why is it reported? #

The @var PHPDoc tag specifies a variable name that does not exist in the current scope. The variable referenced in the tag was never defined before this point in the code and is not being assigned on the line below the tag. This usually indicates a typo in the variable name or a leftover annotation from refactored code.

This is also reported when a @var tag above a multi-variable assignment references a variable that does not exist and is not one of the variables being assigned:

<?php declare(strict_types = 1);

function doBar(string $a): void
{
	/**
	 * @var string $a
	 * @var string $b
	 */
	echo $a;
}

In this example, $b does not exist in the current scope.

How to fix it #

Correct the variable name to match an existing variable in the current scope:

 <?php declare(strict_types = 1);
 
 function doFoo(): void
 {
+	$test = someFunction();
-	/** @var int $foo */
-	echo 'hello';
+	/** @var int $test */
+	echo $test;
 }

Or remove the @var tag if it is no longer needed:

 <?php declare(strict_types = 1);
 
 function doFoo(): void
 {
-	/** @var int $foo */
 	echo 'hello';
 }

How to ignore this error #

You can use the identifier varTag.variableNotFound to ignore this error using a comment:

// @phpstan-ignore varTag.variableNotFound
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.variableNotFound

Rules that report this error #

  • PHPStan\Rules\PhpDoc\WrongVariableNameInVarTagRule [1] [2]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.