Using __METHOD__ always return class name the function belong to. But in some cases (like to make log output), if class B1, B2, B3 inherit class A and call a method of class A, you may would like to see into log which class among B1, B2, B3 is calling.
For example you would like to see:
B1::commond_method_inside_framework
and not
A::commond_method_inside_framework
because you know that common_method_inside_framework is inside common inherited class A.
To solve this, replace __METHOD__ with get_class($this).'::'.__FUNCTION__
class A
{
function commond_method_inside_framework()
{
echo "This is class " . get_class($this).'::'.__FUNCTION__.' '. __METHOD__.' '."\n";
}
}
class B1 extends A
{
function commond_method_inside_caller()
{
echo "This is class " . get_class($this).'::'.__FUNCTION__.' '. __METHOD__.' '."\n";
}
}
$a = new A();
$a->commond_method_inside_framework();
$b = new B1();
$b->commond_method_inside_framework();
$b->commond_method_inside_caller();
?>
Result will be
This is class A::commond_method_inside_framework A::commond_method_inside_framework
This is class B1::commond_method_inside_framework A::commond_method_inside_framework
This is class B1::commond_method_inside_caller B1::commond_method_inside_caller