
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Current Function Name in PHP
To get the current function name in PHP, the code is as follows−
Example
<?php class Base { function display() { echo "
Base class function declared final!"; var_dump(__FUNCTION__); } function demo() { echo "
Base class function!"; } } class Derived extends Base { function demo() { echo "
Derived class function!"; } } $ob = new Base; $ob->demo(); $ob->display(); $ob2 = new Derived; $ob2->demo(); $ob2->display(); ?>
Output
This will produce the following output−
Base class function! Base class function declared final!string(7) "display" Derived class function! Base class function declared final!string(7) "display"
Example
Let us now see another example −
<?php class Base { function display() { echo "
Base class function declared final!"; var_dump(__FUNCTION__); } function demo() { echo "
Base class function!"; var_dump(__METHOD__); } } class Derived extends Base { function demo() { echo "
Derived class function!"; } } $ob = new Base; $ob->demo(); $ob->display(); $ob2 = new Derived; $ob2->demo(); $ob2->display(); ?>
Output
This will produce the following output−
Base class function!string(10) "Base::demo" Base class function declared final!string(7) "display" Derived class function! Base class function declared final!string(7) "display"
Advertisements