Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP get current class name in inherited class

Tags:

oop

php

I have this code in PHP:

abstract class Development
{   
    static function testUnit()
    {
        echo get_class();
    }
}

class Component extends Development
{    
}

But if I am calling Component::testUnit();

I am receiving Development instead of Component. It is puzzling me because such static function has no meaning I guess.

like image 795
Pavel Hanpari Avatar asked Dec 25 '22 20:12

Pavel Hanpari


1 Answers

You want to use get_called_class instead ... http://php.net/manual/en/function.get-called-class.php

like image 85
Jason Byrne Avatar answered Jan 08 '23 01:01

Jason Byrne