How to get the function name inside a function in PHP ?
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 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(); ?> |
GeeksforGeeks
Program 2: PHP program to print the function name inside the function Geeks().
<?php function Geeks() { // Magic function constant which // holds the class method name $string = __METHOD__; // Display the result echo $string; } // Function call Geeks(); ?> |
Geeks
Reference: https://www.php.net/manual/en/language.constants.predefined.php
Recommended Posts:
- How to change the value of a global variable inside of a function using JavaScript ?
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- What happens inside JavaScript Engine ?
- How to dynamically load JS inside JS ?
- CSS | page-break-inside Property
- What purpose does a <script> tag serve inside of a <noscript> tag?
- Add the slug field inside Django Model
- CSS to put icon inside an input element in a form
- Where is an object stored if it is created inside a block in C++?
- How to vertically align text inside a flexbox using CSS?
- JavaScript | Check if a key exists inside a JSON object
- How to perform click-and-hold operation inside an element using jQuery ?
- How to make an image center-aligned (vertically & horizontally) inside a bigger div using CSS?
- How to check a webpage is loaded inside an iframe or into the browser window using JavaScript?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



