Get name of caller function in PHP?

In PHP, the name of the caller function can be obtained using the debug_backtrace() function. The first element in the returned array will contain information about the function that called the current function, including the function name.

Watch a course Learn object oriented PHP

You can access the name of the caller function like this:

<?php

function currentFunction()
{
  $bt = debug_backtrace();
  return $bt[1]['function'];
}

function callerFunction()
{
  return currentFunction();
}

echo callerFunction();

This will return the name of the function that called the current function as a string (callerFunction).