How to get the function name inside a function in PHP ? Last Updated : 25 Sep, 2019 Comments Improve Suggest changes Like Article Like Report To get the function name inside the PHP function we need to use Magic constants(__FUNCTION__). Magic constants: Magic constants are the predefined constants in PHP which is used on the basis of their use. These constants are starts and end with a double underscore (__). These constants are created by various extensions. Syntax: $string = __FUNCTION__ Description: This constant is used to return the function name, or {closure} for anonymous functions. Program 1: PHP program to print function name inside the function GeeksforGeeks(). PHP <?php function GeeksforGeeks() { // Magic function constant which // holds the function name, or // {closure} for anonymous functions $string = __FUNCTION__; // Display the result echo $string; } // Function call GeeksforGeeks(); ?> Output: GeeksforGeeks Program 2: PHP program to print the function name inside the function Geeks(). PHP <?php function Geeks() { // Magic function constant which // holds the class method name $string = __METHOD__; // Display the result echo $string; } // Function call Geeks(); ?> Output: Geeks Reference: https://www.php.net/manual/en/language.constants.predefined.php Comment More infoAdvertise with us Next Article How to get the function name inside a function in PHP ? M Mitrajit Follow Improve Article Tags : Web Technologies PHP PHP Programs PHP-function Similar Reads How to get name of calling function/method in PHP ? Why need to get the name of calling function? The code consist of multiple functions performing different tasks but associated with each other directly or indirectly, and suddenly display an error in some of the functions then it will become necessary to find the name of the function in which an err 3 min read How to get all function names of a module in PHP ? In this article, we will learn How to get the names of all functions present in a module in PHP. What is a module in PHP ? A module is a collection of independent software components. The usage of modules in program improves the code reusability and encapsulation. Module contains functions that we c 2 min read How to get the current file name using PHP script ? In this article, we will learn how to get the current filename using PHP. Input : c:/xampp/htdocs/project/home.php Output : project/home.php Input : c:/xampp/htdocs/project/abc.txt Output : project/abc.txt Sometimes, we need to get the current file name with the directory name in which our page is s 2 min read How to find out where a function is defined using PHP ? When we do projects then it includes multiple modules where each module divided into multiple files and each file containing many lines of code. So when we declare a function somewhere in the files and forget that what the function was doing or want to change the code of that function but can't find 3 min read Function overloading and Overriding in PHP Function overloading and overriding is the OOPs feature in PHP. In function overloading, more than one function can have same method signature but different number of arguments. But in case of function overriding, more than one functions will have same method signature and number of arguments. Funct 3 min read PHP | Check if a variable is a function To determine whether a passed argument is a function or not, Few of the most preferred methods are shown below. Using is_callable() Function: It is an inbuilt function in PHP which is used to verify the contents of a variable in called as a function. It can check that a simple variable contains the 3 min read Anonymous recursive function in PHP Anonymous recursive function is a type of recursion in which function does not explicitly call another function by name. This can be done either comprehensively, by using a higher order function passing in a function as an argument and calling that function. It can be done implicitly, via reflection 2 min read PHP trait_exists() Function PHP implements a way to reuse code called Traits. The trait_exists() function in PHP is an inbuilt function that is used to check whether a trait exists or not. This function accepts the traitname and autoload as parameters and returns true if trait exists, false if not, null in case of an error. Sy 2 min read PHP Callback Functions In PHP, the callback functions are related to the dynamic behavior and flexibility in code execution. They are used to pass custom logic or functions as arguments to other functions, letting developers change how a function behaves without changing its main structure. This makes the code more reusab 5 min read PHP | Magic Constants Magic constants in PHP are special built-in constants that provide information about the current state of the script, such as the file name, line number, function name, class name, and more. They always start and end with double underscores (__) and are automatically used in by PHP.Their values chan 4 min read Like