How do I call child function from parent static function ?
In php5.3 there is a built in method called get_called_class()
to call child method from parent class. But my server is running with php 5.1.
Is there any way can do this ?
I want to call it from a static function . So that I can not use "$this"
So i should use "self" keyword.
Below example my parent class is "Test123" , from the parent class static function "myfunc" am trying to call child class function like this "self::test();"
abstract class Test123
{
function __construct()
{
// some code here
}
public static function myfunc()
{
self::test();
}
abstract function test();
}
class Test123456 extends Test123
{
function __construct()
{
parent::__construct();
}
function test()
{
echo "So you managed to call me !!";
}
}
$fish = new Test123456();
$fish->test();
$fish->myfunc();
$this->parentFunc()
. And no, get_called_class() has not been introduced to call parent functions. -- php.net/manual/en/language.oop5.inheritance.php – hakrestatic
– SahalTest123456::test()
,self
will beTest123
. - see my updated answer for an explanation. – hakre