Php 访问扩展类中的父函数
我正在努力提高php的能力。我有一个关于父类的问题。在下面的代码中,有一种方法可以从Php 访问扩展类中的父函数,php,class,instantiation,extends,Php,Class,Instantiation,Extends,我正在努力提高php的能力。我有一个关于父类的问题。在下面的代码中,有一种方法可以从$b实例化中的类a调用函数foobar()。谢谢 <?php class foo { function callFooBar(){$this->foobar();} function foobar(){echo('foobar of foo');} } class bar extends foo { function foobar(){echo('foobar
$b
实例化中的类a调用函数foobar()。谢谢
<?php
class foo {
function callFooBar(){$this->foobar();}
function foobar(){echo('foobar of foo');}
}
class bar extends foo {
function foobar(){echo('foobar of bar');}
}
$b=new bar;
$b->foobar();
echo("<br>");
$b->callFooBar();
?>
如果要从类本身调用方法,可以使用self
:
function callFooBar(){self::foobar();}
安
使用$this
或static
将获得两次相同的结果
如果要从类bar
中的方法执行此操作,必须使用parent
您是指后期静态绑定吗<代码>函数callFooBar(){static::foobar();}
我不熟悉这个术语。我想使用“$b->something->foobar();”还有“foobar of foo”我知道我可以用“$f=new foo;”但是有没有办法从“b美元”开始呢