Menu

Error Identifier: property.neverWritten

← Back to property.*

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 #

class Queue
{
	private int $anotherProp;

	// Writable property Queue::$count is never written.
	private int $count {
		set {
			$this->anotherProp = $value;
		}
	}

	public function getCount(): int
	{
		return $this->count;
	}
}

Why is it reported? #

The property is declared as writable-only (because it’s a hooked set-only virtual property), but it is never actually written to anywhere in the code. This suggests the property is unused or the write operations are missing. A writable property that is never written serves no purpose.

PHPStan reports this as part of its dead code detection. Unused properties add unnecessary complexity and can indicate incomplete implementations.

How to fix it #

If the property should be written, add the missing write operations:

 	private int $count {
		set {
			$this->anotherProp = $value;
		}
	}

+	public function increment(): void
+	{
+		$this->count++;
+	}
+
 	public function getCount(): int
 	{
 		return $this->count;
 	}
 }

If the property is no longer needed, remove it:

 	private int $anotherProp;
 	
-	private int $count {
-		set {
-			$this->anotherProp = $value;
-		}
-	}
-
-	public function getCount(): int
-	{
-		return $this->count;
-	}
 }

How to ignore this error #

You can use the identifier property.neverWritten to ignore this error using a comment:

// @phpstan-ignore property.neverWritten
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: property.neverWritten

Rules that report this error #

  • PHPStan\Rules\DeadCode\UnusedPrivatePropertyRule [1]
Theme
A
© 2026 PHPStan s.r.o.