Menu
Error Identifier: impure.betweenPhpTags
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 doFoo(): int
{
?><p>Hello</p><?php
return 1;
}
Why is it reported? #
A function marked as @phpstan-pure contains HTML output between PHP opening and closing tags. Pure functions must not have side effects, and outputting HTML to the browser is a side effect.
How to fix it #
Remove the HTML output from the pure function:
<?php declare(strict_types = 1);
/** @phpstan-pure */
function doFoo(): int
{
- ?><p>Hello</p><?php
- return 1;
}
Or remove the @phpstan-pure annotation if the function intentionally produces output.
How to ignore this error #
You can use the identifier impure.betweenPhpTags to ignore this error using a comment:
// @phpstan-ignore impure.betweenPhpTags
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.betweenPhpTags