1.2.1250. Undefined Parent

List of properties and methods that are accessed using parent keyword but are not defined in the parent classes.

This may compile but, eventually yields a fatal error during execution.

Note that if the parent is defined using extends someClass but someClass is not available in the tested code, it will not be reported : it may be in composer, another dependency, or just missing.

<?php

class theParent {
    // No bar() method
    // private bar() method is not accessible to theChild
}

class theChild extends theParent {
    function foo() {
        // bar is defined in theChild, but not theParent
        parent::bar();
    }

    function bar() {

    }
}

?>

See also parent.

1.2.1250.1. Suggestions

  • Remove the usage of the found method

  • Add a definition for the method in the appropriate parent

  • Fix the name of the method, and replace it with a valid definition

  • Change ‘parent’ with ‘self’ if the method is eventually defined in the current class

  • Change ‘parent’ with another object, if the method has been defined in another class

  • Add the ‘extends’ keyword to the class, to actually have a parent class

1.2.1250.2. Specs

Short name

Classes/UndefinedParentMP

Rulesets

All, Analyze

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

parent

Available in

Entreprise Edition, Exakat Cloud