为什么父类中可以调用子类的方法?
abstract class A {
private $name;
function __construct($param){
$this->name = 'liming'.'<br>';
}
function getName() {
echo $this->name;
}
// 调用子类中的方法getAge2
function getAge() {
$this->getAge2();
}
function getAge3() {
return '23';
}
}
class B extends A {
function getAge2(){
echo $this->getAge3();
}
}
$a = new B('a');
$a->getName();
$a->getAge();
工画堂喵的猫
9 years, 8 months ago
Answers
脑袋思维定势了吧,为何不
(new A)->getAge()
试试?
http://3v4l.org/cMZjE
Shrori
answered 9 years, 8 months ago