Menu
Error Identifier: return.phpDocType
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);
/**
* @return string
*/
function doFoo(): int
{
return 1;
}
Why is it reported? #
The @return PHPDoc tag specifies a type that is incompatible with the native return type. In the example above, the PHPDoc says the function returns string, but the native return type is int. These types are incompatible.
How to fix it #
Align the PHPDoc type with the native return type:
<?php declare(strict_types = 1);
/**
- * @return string
+ * @return int
*/
function doFoo(): int
{
return 1;
}
How to ignore this error #
You can use the identifier return.phpDocType to ignore this error using a comment:
// @phpstan-ignore return.phpDocType
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: return.phpDocType