-- Drupal and Web Development

Notice: this post was last updated 3 years 13 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:

* Returns the calling function through a backtrace
function get_calling_function() {
// a funciton x has called a function y which called this
  // see
$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']) . ')';

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.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.