Home > Article > Backend Development > How to get the current function name in PHP? (code example)
In PHP, we can use the magic constant __FUNCTION__ or __METHOD__ to easily obtain the function name. The following article will give you a detailed understanding. I hope it will be helpful to everyone.
Method 1: Use __FUNCTION__
Magic constant __FUNCTION__ is used for parsing Function name or method name (function in class), function name can be returned.
Example:
<?php class Test { public function bar() { var_dump(__FUNCTION__); } } function foo() { var_dump(__FUNCTION__); } foo(); $obj = new Test; $obj->bar(); ?>
Output:
##Method 2: Use __METHOD__
Magic constant __METHOD__ can return function and class names. Code example:<?php class Test { public function foo() { var_dump(__METHOD__); } } function bar() { var_dump(__METHOD__); } bar(); $obj = new Test; $obj->foo(); ?>Output: ##Note:
Magic constants __FUNCTION__ and __METHOD__ Retrieving function names is case-sensitive. Related recommendations: "
PHP Tutorial"The above is the entire content of this article, I hope it will be helpful to everyone's learning. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !
The above is the detailed content of How to get the current function name in PHP? (code example). For more information, please follow other related articles on the PHP Chinese website!