Get the name of the executing function through the FUNCTION magic constant in PHP: Syntax: $function_name = __FUNCTION__; Usage: Use FUNCTION inside the function to get the name of the calling function; Note: It can only be used inside the function, and only the function name is returned. , does not contain a namespace or class name, and returns an empty string when used as an anonymous function.
#How does a PHP function return the function name?
A powerful feature in PHP is the ability to get the name of the function being executed via the __FUNCTION__
magic constant. This constant can be used inside a function to get the name of the calling function.
Syntax:
$function_name = __FUNCTION__;
Practical case:
The following is an example of getting the function name inside the function:
function get_function_name() { echo "当前函数名:" . __FUNCTION__; } get_function_name();
This code will output:
当前函数名:get_function_name
Other notes:
__FUNCTION__
Constants can only be used inside functions . __FUNCTION__
will return an empty string. The above is the detailed content of How does a PHP function return the function name?. For more information, please follow other related articles on the PHP Chinese website!