作者:shahua1111 | 来源:互联网 | 2020-11-28 06:30
php访问父类方法的办法:可以用【$this->方法名();】来访问,如果子类中有该方法,则访问的是子类中的方法,如果子类中没有该方法,则访问父类中的方法。
";
}
}
class B extends A{//若A类和B类不在同一文件中 请包含后(include)再操作
public $a1='b1';
function test2(){
$this->test();
parent::test();//子类调用父类方法
}
function test()
{
echo $this->a1.',';
echo $this->a2.',';
echo "b2_test_hello
";
}
}
$a = new B();
$a->test();//b1,a2,b2_test_hello
$a->test2();//b1,a2,b2_test_hello//hello!