Menu

← Back to impure.*

Error Identifier: impure.die

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);

class Foo
{
	/** @phpstan-pure */
	public function doFoo(): string
	{
		die('fatal error');
	}
}

Why is it reported? #

The die language construct is used inside a function or method marked as @phpstan-pure. Pure functions must not have side effects – they should only compute and return a value based on their inputs. Calling die terminates the entire PHP process, which is a significant side effect.

How to fix it #

Remove die from the pure function by throwing an exception instead, or remove the @phpstan-pure annotation if the function genuinely needs to terminate the process:

 <?php declare(strict_types = 1);
 
 class Foo
 {
 	/** @phpstan-pure */
 	public function doFoo(): string
 	{
-		die('fatal error');
+		throw new \RuntimeException('fatal error');
 	}
 }

Or remove the purity annotation:

 <?php declare(strict_types = 1);
 
 class Foo
 {
-	/** @phpstan-pure */
 	public function doFoo(): string
 	{
 		die('fatal error');
 	}
 }

How to ignore this error #

You can use the identifier impure.die to ignore this error using a comment:

// @phpstan-ignore impure.die
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.die

Rules that report this error #

  • PHPStan\Rules\Pure\PureFunctionRule [1]
  • PHPStan\Rules\Pure\PureMethodRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.