<?php class A{ function test(){ echo "hello!"; } } class B extends A{//若A类和B类不在同一文件中 请包含后(include)再操作 function test2(){ parent::test();//子类调用父类方法 echo "test2"; } } $a = new B(); $a->test();//hello! $a->test2();//hello!test2 ?>
parent::test();//子类调用父类方法 to$this->test(); // as the same
class A{ function test(){ echo "hello!<hr/>"; } } class B extends A{//若A类和B类不在同一文件中 请包含后(include)再操作 function test2(){ parent::test();//子类调用父类方法 } function test() { echo "b2_test_hello<hr/>"; } } $a = new B(); $a->test();//hello! $a->test2();//hello!test2/** parent::test();一直是调用父类的。 而 $this->test() 则是子类没有申明时调用父类的方法,子类有这个方法时,则调用的是子类自己的方法 $a->test();//b2_test_hello -------------------------------------------------------------------------------- $a->test2();//hello**/
class A{
function test(){
echo "hello!";
}
}
class B extends A{//若A类和B类不在同一文件中 请包含后(include)再操作
function test2(){
parent::test();//子类调用父类方法
echo "test2";
}
}
$a = new B();
$a->test();//hello!
$a->test2();//hello!test2
?>
parent::test();//子类调用父类方法 to$this->test(); // as the same
function test(){
echo "hello!<hr/>";
}
}
class B extends A{//若A类和B类不在同一文件中 请包含后(include)再操作
function test2(){
parent::test();//子类调用父类方法
}
function test()
{
echo "b2_test_hello<hr/>";
}
}
$a = new B();
$a->test();//hello!
$a->test2();//hello!test2/** parent::test();一直是调用父类的。 而 $this->test() 则是子类没有申明时调用父类的方法,子类有这个方法时,则调用的是子类自己的方法
$a->test();//b2_test_hello
--------------------------------------------------------------------------------
$a->test2();//hello**/