Error Identifier: property.missingNativeType
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
{
public int $value = 0;
}
class Child extends Base
{
/** @var int */
public $value = 0;
}
Why is it reported? #
The parent class declares a property with a native type, but the overriding property in the child class does not have a native type declaration. When a parent property has a native type, the child property must also declare the same native type to maintain type safety. Omitting the native type in the child class creates an inconsistency that PHP will reject at runtime.
How to fix it #
Add the matching native type declaration to the overriding property:
<?php declare(strict_types = 1);
class Base
{
public int $value = 0;
}
class Child extends Base
{
- /** @var int */
- public $value = 0;
+ public int $value = 0;
}
How to ignore this error #
You can use the identifier property.missingNativeType to ignore this error using a comment:
// @phpstan-ignore property.missingNativeType
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.missingNativeType
Rules that report this error #
- PHPStan\Rules\Properties\OverridingPropertyRule [1]