Error Identifier: property.extraNativeType
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 $name;
}
class Child extends Base
{
public int $name;
}
Why is it reported? #
The child class declares a native type on a property that has no native type in the parent class. When a parent property is untyped, the child property must also remain untyped. Adding a native type in the child would change the property’s type contract, which PHP does not allow.
How to fix it #
Remove the native type from the child property to match the parent:
class Child extends Base
{
- public int $name;
+ public $name;
}
Alternatively, add the native type to the parent property first, then the child can match it:
class Base
{
- public $name;
+ public int $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\OverridingPropertyRule [1]