The php Function Get_Class
The php function get_class is used to return the name of a class. It is an essential function for object oriented programming. Object inheritance is a key feature of many languages including PHP. It allows public methods, class properties and constants to be overridden by classes that extend them. Class B in the following script extends class A and reimplements the sortArray method from A. This override makes class A’s method a public method in B.
The problem with this is that you can only receive inherited methods in the context where the caller has class reference control. That means that if you are calling a static function from another class, the name of the calling class will be returned and not the class being called. This is because of Late Static Binding.
In PHP 5, you can use the __CLASS__ constant to pass the name of the calling class to a static function in an extended class. This is the only way to get a static function name in an extended class to work correctly.
However, if you are calling this from outside of the class, or from a function within the same class, or from a variable, then it raises a TypeError error. As of PHP 8.0, this function will now only return an object if the input is not null or an integer. This change is to make the function compatible with namespaces.