website/errors/possiblyImpure.exit.md
<?php declare(strict_types = 1);
/**
* @phpstan-pure
*/
function getValue(int $input): int
{
$closure = function () {
exit();
};
$closure();
return $input * 2;
}
This identifier is not reported in practice because exit is always considered definitely impure, not just possibly impure. PHPStan reports impure.exit instead.
The function or method is marked as @phpstan-pure but may call exit or die. These constructs terminate the entire PHP process, which is a side effect. Pure functions must not have side effects; they should only compute and return a value based on their inputs.
Remove the exit/die call from the pure function, or remove the @phpstan-pure annotation if process termination is intentional:
/**
- * @phpstan-pure
+ * @phpstan-impure
*/
function getValue(int $input): int
{
$closure = function () {
exit();
};
$closure();
return $input * 2;
}