Menu

← Back to possiblyImpure.*

Error Identifier: possiblyImpure.propertyUnset

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
{
	public ?string $name = null;

	/** @phpstan-pure */
	public function reset(): void
	{
		unset($this->name);
	}
}

Why is it reported? #

The function or method is marked as @phpstan-pure, meaning it must not cause side effects. Unsetting a property modifies object state, which is a side effect. Since the object might be referenced elsewhere, this mutation is possibly impure.

How to fix it #

Remove the @phpstan-pure annotation if the method intentionally modifies state:

-/** @phpstan-pure */
 public function reset(): void
 {
 	unset($this->name);
 }

Or restructure the code to avoid mutating properties in a pure context:

 /** @phpstan-pure */
-public function reset(): void
-{
-	unset($this->name);
-}
+public function withoutName(): static
+{
+	$clone = clone $this;
+	$clone->name = null;
+	return $clone;
+}

How to ignore this error #

You can use the identifier possiblyImpure.propertyUnset to ignore this error using a comment:

// @phpstan-ignore possiblyImpure.propertyUnset
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: possiblyImpure.propertyUnset

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.