In the sample code below, the method test()
in parent class Foo
is overridden by the method test()
in child class Bar
. Is it possible to call Foo::test()
from Bar::test()
?
class Foo
{
$text = "world\n";
protected function test() {
echo $this->text;
}
}// class Foo
class Bar extends Foo
{
public function test() {
echo "Hello, ";
// Cannot use 'parent::test()' because, in this case,
// Foo::test() requires object data from $this
parent::test();
}
}// class Bar extends Foo
$x = new Bar;
$x->test();
foo::test() REQUIRE_DISABLED object data from $this