Drupal debugging tips: views_trace()

By | 11th May 2012 | 1 min read

As a Drupal developer, when we get an error, we may want to know the functions that are called before the system called the function where we get the error. In this case, views_trace() function comes to your help. This function is available if Drupal’s Views module is installed and enabled.

Here is the function from views.module

function views_trace() {
  $message = '';
  foreach (debug_backtrace() as $item) {
    if (!empty($item['file']) && !in_array($item['function'], array('vsm_trace', 'vpr_trace', 'views_trace'))) {
      $message .= basename($item['file']) 
        .": ". (empty($item['class']) ? '' : ($item['class'] .'->')) 
        ."$item[function] line $item[line]"
  return $message;