Error Identifier: phpstan.variable
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);
use function PHPStan\Testing\assertVariableCertainty;
use PHPStan\TrinaryLogic;
function doFoo(): void
{
if (rand(0, 1)) {
$a = 1;
}
assertVariableCertainty(TrinaryLogic::createYes(), $a);
}
Why is it reported? #
This is an internal testing function used in PHPStan’s test suite. The assertVariableCertainty() call expects a specific certainty level for a variable (Yes, No, or Maybe), but the actual certainty level is different. In the example above, the variable $a might or might not exist (certainty: Maybe), but the assertion expects it to always exist (certainty: Yes).
How to fix it #
Fix the expected certainty to match the actual state:
<?php declare(strict_types = 1);
-assertVariableCertainty(TrinaryLogic::createYes(), $a);
+assertVariableCertainty(TrinaryLogic::createMaybe(), $a);
Non-ignorable error #
This error cannot be ignored using @phpstan-ignore or the ignoreErrors configuration. Non-ignorable errors indicate code that would cause a crash or a fatal error at runtime, or a fundamental problem in the analysed code that must be addressed.
Rules that report this error #
- PHPStan\Rules\Debug\FileAssertRule [1]