Retrieving the name of the current function in PHP

PhpFunction

Php Problem Overview


Is there a function that can return the name of the current function a program is executing?

Php Solutions


Solution 1 - Php

Yes, you can get the function's name with the magic constant __FUNCTION__

class foo
{
  function print_func()
  {
            echo __FUNCTION__;
  }
  function print_method()
  {
            echo __METHOD__;
  }
}

$obj = new foo();
$obj->print_func();      // Returns: print_func
$obj->print_method();    // Returns: foo::print_method

Solution 2 - Php

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCian EView Question on Stackoverflow
Solution 1 - PhpSarfrazView Answer on Stackoverflow
Solution 2 - PhprobertbasicView Answer on Stackoverflow