Getting an error inside a core function? Infinite Redirect? debug_backtrace() to the rescue!

Published April 20, 2011

We are all very familiar with the White Screen of Death in the Drupal world, AKA WSOD. One very common cause is a lack of memory for PHP - yet another is having errors turned off.

In development mode, you should probably make sure you are showing PHP errors on the screen, if this is an option. This is the kind of thing you can edit in your site-specific settings.php file, by using:

{syntaxhighlighter brush: php;fontsize: 100; first-line: 1; }error_reporting(E_ALL); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); {/syntaxhighlighter}

Once you get there, a lot of times, the error you see on the screen is from a core Drupal function, or something even more generic like "array_merge expects parameter 2 to be array". In these cases, it can be incredibly helpful to figure out what function was called, which module it was called from, and what parameters were passed to the function.

The questions I want to answer is "which function called this function?" Sometimes, that's hard to figure out. One easy way to debug is with the debug_backtrace() function.

Depending on how bad your error is, you might be able to call:

{syntaxhighlighter brush: php;fontsize: 100; first-line: 1; }dsm(debug_backtrace()); {/syntaxhighlighter}

if your page is hitting a white screen, you might want to try:

{syntaxhighlighter brush: php;fontsize: 100; first-line: 1; }print_r(debug_backtrace()); die();{/syntaxhighlighter}


Note: dsm() only works if you have the devel module installed, and the currently logged in user has the "access devel information" permission. If the error is only occurring for anonymous users, for example, you will need to temporarily grant this permission to the Anonymous role.

See also:…


I've search for something like this.
I've have a question.

On my /admin/reports/ 'age not found'-errors page, I have an broken reference to a png-file in a css-file. The problem is, that i can't find find function called that png-file.

How is it possible to do debug_backtrace on a already generated watchdog-log? I have gone through the whole site without finding the broken reference.

Hope you have an idea!?

Submitted by Guest (not verified) on Tue, 10/04/2011 - 09:08

Make sure the file is actually there, and the css rule is not misspelled or with captial letters in the wrong place. like .png vs. .PNG - that used to matter in the old days.


My guess is you could get the error to go away by editing the css rule.

I'm guessing there is a rule like this:


In the worst case you could make this a relative link to the site root


Sometimes you can get by with something more subtle:


Submitted by admin on Thu, 10/06/2011 - 11:02

In reply to by Guest (not verified)

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!