我有以下课程结构
class A
{
function aa(){
//do something in aa
$this->ab();
}
function ab(){
//do something in ab
}
}
Class B extends A
function ab(){
//do something else in ab
}
}
$b = new B();
$b->aa();
当我从B类的对象调用aa()时,如何覆盖方法ab,以确保从B类调用它?
答案 0 :(得分:1)
B类 - > ab()调用;
<?php
class A
{
function aa(){
//do something in aa
$this->ab();
}
function ab(){
//do something in ab
echo "class A\n";
}
}
Class B extends A {
function ab(){
//do something else in ab
echo "class B\n";
}
}
$b = new B();
$b->aa();