PHP Parent Method Call Guide

In PHP, you can use the keyword parent:: to reference a method in the parent class. For example, calling a method from the parent class in a subclass can be done like this:

class ParentClass {
    public function parentMethod() {
        echo "This is parent method";
    }
}

class ChildClass extends ParentClass {
    public function childMethod() {
        parent::parentMethod();
    }
}

$child = new ChildClass();
$child->childMethod(); //输出:This is parent method

Call the parentMethod() method of the parent class in a subclass method using parent::parentMethod().

bannerAds