php拜访父类办法的方法:能够用【$this->办法名();】来拜访,假如子类中有该办法,则拜访的是子类中的办法,假如子类中不该办法,则拜访父类中的办法。
办法的挪用:
$this->办法名();假如子类中有该办法则挪用的是子类中的办法,若不则是挪用父类中的。
parent::则始终挪用的是父类中的办法。
(保举教程:php视频教程)
变量的挪用:$this->变量名;假如子类中有该变量则挪用的是子类中的,若不则挪用的是父类中的
代码完成:
<?php class A{ public $a1='a1'; protected $a2='a2'; function test(){ echo "hello!<hr/>"; } } 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<hr/>"; } } $a = new B(); $a->test();//b1,a2,b2_test_hello $a->test2();//b1,a2,b2_test_hello//hello!
相干保举:php培训
以上就是php若何拜访父类办法的具体内容,更多请存眷资源魔其它相干文章!
标签: php php教程 php故障解决 php使用问题 父类方法
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!