mediatribe.net -- Drupal and Web Development

Notice: this post was last updated 3 years 16 weeks ago so it might be outdated. Please be cautious before implementing any of suggestions herein.

In PHP, getting the calling function

In PHP, if you want to know the function that called whatever function you are currently in, you can define something like:

<?php
/**
* Returns the calling function through a backtrace
*/
function get_calling_function() {
 
// a funciton x has called a function y which called this
  // see stackoverflow.com/questions/190421
 
$caller = debug_backtrace();
 
$caller = $caller[2];
 
$r = $caller['function'] . '()';
  if (isset(
$caller['class'])) {
   
$r .= ' in ' . $caller['class'];
  }
  if (isset(
$caller['object'])) {
   
$r .= ' (' . get_class($caller['object']) . ')';
  }
  return
$r;
}
?>

What's Happening i am new to

What's Happening i am new to this, I stumbled upon this
I have found It positively helpful and it has aided
me out loads. I hope to give a contribution & help other customers like
its aided me. Good job.