Error Identifier: parameter.noParent
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 Foo
{
public function doFoo(parent $value): void
{
}
}
Why is it reported? #
The parent type is used in a parameter declaration, but the class does not have a parent class. The parent keyword refers to the parent class in the inheritance hierarchy, and it can only be used in classes that extend another class. Using parent in a class that does not extend anything causes a fatal error at runtime.
How to fix it #
If the class should have a parent, add the extends clause:
-class Foo
+class Foo extends Bar
{
public function doFoo(parent $value): void
{
}
}
If parent was used by mistake, replace it with the intended type:
class Foo
{
- public function doFoo(parent $value): void
+ public function doFoo(self $value): void
{
}
}
How to ignore this error #
You can use the identifier parameter.noParent to ignore this error using a comment:
// @phpstan-ignore parameter.noParent
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: parameter.noParent
Rules that report this error #
- PHPStan\Rules\Functions\ExistingClassesInArrowFunctionTypehintsRule [1]
- PHPStan\Rules\Functions\ExistingClassesInClosureTypehintsRule [1]
- PHPStan\Rules\Functions\ExistingClassesInTypehintsRule [1]
- PHPStan\Rules\Methods\ExistingClassesInTypehintsRule [1]
- PHPStan\Rules\Properties\ExistingClassesInPropertyHookTypehintsRule [1]