Menu

Error Identifier: purePropertyHook.void

← Back to purePropertyHook.*

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

final class Foo
{
	private int $backing = 1;

	public int $value {
		/** @phpstan-pure */
		set {
			$this->backing = $value; // ERROR: Set hook for property Foo::$value is marked as pure but returns void.
		}
	}
}

Why is it reported? #

A property hook (PHP 8.4+) marked as @phpstan-pure must not have side effects and must produce a meaningful value. A set hook always returns void, so a pure set hook can neither return a value nor legitimately do anything: assigning to the backing value is itself a side effect. Marking a set hook as pure is therefore contradictory.

The same applies to any hook that returns void: without side effects and without a return value, invoking it has no observable effect, which is almost certainly a mistake.

How to fix it #

A set hook exists to mutate state, so it is inherently impure. Remove the @phpstan-pure annotation:

 public int $value {
-	/** @phpstan-pure */
 	set {
 		$this->backing = $value;
 	}
 }

If you meant to mark the read side of the property, put @phpstan-pure on the get hook, which returns a value:

 public int $value {
+	/** @phpstan-pure */
 	get => $this->backing;
 }

How to ignore this error #

You can use the identifier purePropertyHook.void to ignore this error using a comment:

// @phpstan-ignore purePropertyHook.void
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: purePropertyHook.void

Rules that report this error #

  • PHPStan\Rules\Pure\PureFunctionRule [1]
  • PHPStan\Rules\Pure\PureMethodRule [1]
  • PHPStan\Rules\Pure\PurePropertyHookRule [1]
Theme
A
© 2026 PHPStan s.r.o.