I have a clase Base in PHP for inherit it to many children classes, managing errors into Base class, I try to print in screen where the error occurs, Can I get the child class name to show in the error during the Exception in Base parent Class?
Yes you can using get_class()
class Base{
public function printBase(){
echo get_class($this);
}
}
class Ext extends Base{}
$ext = new Ext();
$ext->printBase(); //Output: Ext
The function get_called_class() resolve my problem, this throws the name of the class who is calling. http://php.net/manual/es/function.get-called-class.php