Menu
Error Identifier: impure.echo
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);
/** @phpstan-pure */
function format(string $name): string
{
echo "Formatting: $name";
return strtoupper($name);
}
Why is it reported? #
A function marked as @phpstan-pure contains an echo statement. Pure functions must not have side effects, and echo produces output, which is a side effect.
How to fix it #
Remove the echo statement from the pure function:
<?php declare(strict_types = 1);
/** @phpstan-pure */
function format(string $name): string
{
- echo "Formatting: $name";
return strtoupper($name);
}
Or remove the @phpstan-pure annotation if the function intentionally produces output.
How to ignore this error #
You can use the identifier impure.echo to ignore this error using a comment:
// @phpstan-ignore impure.echo
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: impure.echo