Error Identifier: property.neverWritten
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 Queue
{
private(set) int $count = 0;
public function getCount(): int
{
return $this->count;
}
}
Why is it reported? #
The property is declared as writable-only (using asymmetric visibility with private(set) or similar), 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:
<?php declare(strict_types = 1);
class Queue
{
private(set) int $count = 0;
+ public function increment(): void
+ {
+ $this->count++;
+ }
+
public function getCount(): int
{
return $this->count;
}
}
If the property is no longer needed, remove it:
<?php declare(strict_types = 1);
class Queue
{
- private(set) int $count = 0;
-
- 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]