I'm fairly new to OOP and I'm trying to get the name of the currently executing class and method. For example:
<?php
class ParentExample
{
function __construct()
{
echo get_class($this) . '<br />';
echo __METHOD__;
exit;
}
}
class ChildExample extends ParentExample
{
public static function test()
{
echo 'hello';
}
}
call_user_func_array([new ChildExample, test]);
This is the result I want:
ChildExample
ChildExample::test
This is the result I get:
ChildExample
ParentExample::__construct
I've looked at debug_backtrace() but I don't understand how to decipher the results or if that's even what I need. Is there an easier way to achieve what I'm after?
EDIT: Based on the answers I think my question isn't clear. I want the ParentExample constructor to tell me the name of the called method. Is this possible?