Menu

← Back to property.*

Error Identifier: property.hookWithoutBody

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 Person
{
	public string $name { get; set; }
}

Why is it reported? #

In PHP 8.4+, property hooks (get and set) must have a body unless the property is declared abstract in an abstract class. A hook without a body (e.g., get; instead of get { ... }) is only valid for abstract properties, where the implementation is deferred to child classes.

In the example above, Person is not abstract and the property $name is not abstract, so the hooks must provide their implementation bodies.

How to fix it #

Add bodies to the property hooks:

 <?php declare(strict_types = 1);
 
 class Person
 {
-	public string $name { get; set; }
+	public string $name {
+		get => $this->name;
+		set => $this->name = $value;
+	}
 }

Or if the intention is to defer the implementation, declare both the class and the property as abstract:

 <?php declare(strict_types = 1);
 
-class Person
+abstract class Person
 {
-	public string $name { get; set; }
+	abstract public string $name { get; set; }
 }

Or remove the hooks entirely if the property does not need custom get/set logic:

 <?php declare(strict_types = 1);
 
 class Person
 {
-	public string $name { get; set; }
+	public string $name;
 }

Non-ignorable error #

This error cannot be ignored using @phpstan-ignore or the ignoreErrors configuration. Non-ignorable errors indicate code that would cause a crash or a fatal error at runtime, or a fundamental problem in the analysed code that must be addressed.

Rules that report this error #

  • PHPStan\Rules\Properties\PropertyInClassRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.