Code Inspection: Possible polymorphic call
Reports polymorphic code usages. Such usages are ambiguous and can be potentially inoperable depending on the class instance passed as the argument.
In the following example, the $property
property is only defined in ChildClass
but not in ParentClass
. As a result, the getProperty
function call is operable when a ChildClass
instance is passed as an argument, but inoperable when a ParentClass
instance is passed.
class ParentClass {
}
class ChildClass extends ParentClass {
public $property = 1;
}
function getProperty(ParentClass $a) {
echo $a->property;
}
getProperty(new ChildClass()); //will work, since $property is defined in Child
getProperty(new ParentClass()); //won't work, since $property is not defined in Parent
Suppress an inspection in the editor
Position the caret at the highlighted line and press Alt+Enter or click .
Click the arrow next to the inspection you want to suppress and select the necessary suppress action.
Last modified: 16 July 2021