Menu

← Back to property.*

Error Identifier: property.unused

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
{
	private int $unused;

	public function __construct()
	{
	}
}

Why is it reported? #

A private property that is never read and never written is dead code. It occupies space in the class definition and in every instance, but serves no purpose. This usually indicates leftover code from a refactoring or a property that was declared but never integrated into the class logic.

How to fix it #

Remove the unused property if it is no longer needed:

 <?php declare(strict_types = 1);
 
 class Foo
 {
-	private int $unused;
-
 	public function __construct()
 	{
 	}
 }

Or start using the property if it was intended to be part of the class:

 <?php declare(strict_types = 1);
 
 class Foo
 {
 	private int $unused;

-	public function __construct()
+	public function __construct(int $value)
 	{
+		$this->unused = $value;
+	}
+
+	public function getValue(): int
+	{
+		return $this->unused;
 	}
 }

If the property is read or written through a mechanism not visible to PHPStan (such as reflection, serialization, or a custom magic method), a custom extension can be used to inform PHPStan about the usage.

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\DeadCode\UnusedPrivatePropertyRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.