Error Identifier: return.empty
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(): string
{
return;
}
Why is it reported? #
A bare return; statement (without a value) is used in a function that declares a non-void return type. In the example above, the function is declared to return string, but the return statement does not provide a value.
How to fix it #
Return a value that matches the declared return type:
<?php declare(strict_types = 1);
function doFoo(): string
{
- return;
+ return '';
}
Or change the return type to void if the function is not meant to return a value.
How to ignore this error #
You can use the identifier return.empty to ignore this error using a comment:
// @phpstan-ignore return.empty
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.empty