我们可以调用类的父方法吗


Can we call parent method out side of the class

我有如下的父类和子类:

// class A
class A {
    public function test(){
        echo "CLASS A";
    }
}
// class b which is extending class A
class B extends A{
    public function test(){        
        echo "CLASS B";
    }
}
$class = new B;
$class->test();  //It's calling child class function.

有什么方法可以用$class调用父类方法吗?我知道我也可以为类a创建一个对象并调用函数,但我想从子类对象调用父类方法。

这在php中可能吗?

试用:

class B extends A{
    public function test(){        
        echo parent::test();
    }
}

更多详细信息请点击此处:http://php.net/manual/en/keyword.parent.php