如何向子方法添加更多功能


How do I add more functionality to child method?

parent_says() 方法说明了一些事情,现在我想为 parent_says() 方法添加更多功能,但从子类内部。我该怎么做?

    class Parent_class{
    function parent_says(){
        echo "HI. I'm parent!";
    }
}
class Child_class extends Parent_class{
    function parent_says(){
        //I want it to also says "HI. I'm parent!", that's inside parent method.
        echo "I say hello!";
    }
}
$Child_class = new Child_class;
$Child_class->parent_says();

使用 parent:: 首先调用父类的方法。 例如

class Child_class extends Parent_class{
    function parent_says(){
        parent::parent_says();
        echo "I say hello!";
    }
}

有关更多信息,请参阅此处。