Menu

Error Identifier: propertyGetHook.noRead

← Back to propertyGetHook.*

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 User
{

	public string $fullName {
		get {
			return "John Doe";
		}
		set {
			$this->fullName = $value;
		}
	}

	public function __construct(
		public string $firstName,
		public string $lastName,
	)
	{
	}

}

Why is it reported? #

The get hook of a non-virtual property does not read the property’s backing value. A non-virtual property (one that has a backing store because it has a set hook that writes to $this->propertyName) has its own stored value, and the get hook is expected to read that value. If the get hook returns a completely independent value without reading the property, the stored value becomes unused and the property should likely be virtual (without a backing value) instead.

In the example above, the set hook writes to $this->fullName, making the property non-virtual. But the get hook ignores the stored value and returns a hardcoded string.

How to fix it #

Read the property’s value in the get hook:

 class User
 {

 	public string $fullName {
 		get {
-			return "John Doe";
+			return $this->fullName;
 		}
 		set {
 			$this->fullName = $value;
 		}
 	}

 	public function __construct(
 		public string $firstName,
 		public string $lastName,
 	)
 	{
 	}

 }

Or make the property virtual by removing the set hook and computing the value from other properties:

 class User
 {

 	public string $fullName {
 		get {
-			return "John Doe";
+			return $this->firstName . ' ' . $this->lastName;
 		}
-		set {
-			$this->fullName = $value;
-		}
 	}

 	public function __construct(
 		public string $firstName,
 		public string $lastName,
 	)
 	{
 	}

 }

How to ignore this error #

You can use the identifier propertyGetHook.noRead to ignore this error using a comment:

// @phpstan-ignore propertyGetHook.noRead
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: propertyGetHook.noRead

Rules that report this error #

  • PHPStan\Rules\Properties\GetNonVirtualPropertyHookReadRule [1]
Theme
A
© 2026 PHPStan s.r.o.