Menu

← Back to property.*

Error Identifier: property.neverRead

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 ?string $name {
		get => $this->items[$this->index] ?? null;
	}

	/** @var string[] */
	public array $items = [];

	private int $index = 0;

	public function setIndex(int $i): void
	{
		$this->index = $i;
	}
}

Why is it reported? #

The property is readable (has a get hook) but is never actually read anywhere in the code. This indicates dead code – a property that provides a read interface but has no consumers. Since the property is private, it can only be accessed within the class, and PHPStan has verified it is never read there.

How to fix it #

Remove the property if it is no longer needed:

 class Foo
 {
-	private ?string $name {
-		get => $this->items[$this->index] ?? null;
-	}
-
 	/** @var string[] */
 	public array $items = [];

 	private int $index = 0;
 }

Alternatively, if the property should be read, add the missing read access in the class.

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\DeadCode\UnusedPrivatePropertyRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.