Menu

← Back to property.*

Error Identifier: property.nativeType

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 Base
{
	protected int $value;
}

class Child extends Base
{
	protected string $value; // ERROR: Type string of property Child::$value is not the same as type int of overridden property Base::$value.
}

Why is it reported? #

When a child class overrides a property from a parent class, the native type of the overriding property must match the native type of the parent property. PHP enforces property type invariance for read-write properties. For properties that are only readable or only writable (via property hooks in PHP 8.4+), covariance or contravariance rules apply respectively.

This error is not ignorable because it represents a PHP language-level constraint that would cause a fatal error at runtime.

How to fix it #

Make the child property’s native type match the parent property’s native type:

 <?php declare(strict_types = 1);
 
 class Child extends Base
 {
-	protected string $value;
+	protected int $value;
 }

If the child class needs to narrow the type, use a @var PHPDoc type annotation while keeping the native type the same:

 <?php declare(strict_types = 1);
 
 class Child extends Base
 {
-	protected string $value;
+	/** @var positive-int */
+	protected int $value;
 }

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\OverridingPropertyRule [1] [2] [3]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.