1.2.142. Class Without Parent

Classes should not refer to parent when it is not extending another class.

In PHP 7.4, it is a Deprecated warning. In PHP 7.3, it was a Fatal error, when the code was eventually executed. In PHP 8.0, PHP detects this error at compile time, except for parent keyword in a closure <https://www.php.net/`closure>`_.

parent usage in trait is detected. It is only reported when the trait is used inside a class without parent, as the trait may also be used in another class, which has a parent.

<?php

class x {
    function foo() {
        parent::foo();
    }
}
?>

1.2.142.1. Suggestions

  • Update the class and make it extends another class

  • Change the parent mention with a fully qualified name

  • Remove the call to the parent altogether

1.2.142.2. Specs

Short name

Classes/NoParent

Rulesets

All, Analyze, CE, CI-checks, Changed Behavior, Class Review

Exakat since

1.9.0

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Changed Behavior

PHP 8.0 - More

Precision

Very high

Features

parent

Available in

Entreprise Edition, Community Edition, Exakat Cloud