note 116025 added to language.constants.predefined
| From: | eldy at destailleur dot fr | Date: | Thu, 30 Oct 2014 17:52:40 +0000 |
| Subject: | note 116025 added to language.constants.predefined | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200753@lists.php.net to get a copy of this message | ||
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
----
Server IP: 72.52.91.14
Probable Submitter: 185.10.252.128
----
Manual Page -- http://php.net/manual/en/language.constants.predefined.php
Edit -- https://master.php.net/note/edit/116025
Del: integrated -- https://master.php.net/note/delete/116025/integrated
Del: useless -- https://master.php.net/note/delete/116025/useless
Del: bad code -- https://master.php.net/note/delete/116025/bad+code
Del: spam -- https://master.php.net/note/delete/116025/spam
Del: non-english -- https://master.php.net/note/delete/116025/non-english
Del: in docs -- https://master.php.net/note/delete/116025/in+docs
Del: other reasons-- https://master.php.net/note/delete/116025
Reject -- https://master.php.net/note/reject/116025
Search -- https://master.php.net/manage/user-notes.php