<?php
class MyParent {
public static function tellSomething() {
return __CLASS__;
}
}
class MyChild extends MyParent {
}
echo MyChild::tellSomething();
The code above echos “MyParent”. How can i get to name of child class – in this case “MyChild”? If it’s possible…
I just simply need to know which child is calling the inherited method.
__CLASS__is a pseudo-constant, that always refers to the class, where it is defined. Withlate-static-bindingthe functionget_called_class()were introduced, that resolve the classname during runtime.(as a sidenote: usually methods don’t need to know the class on were they are called)