Community Documentation

Show all errors while developing

Last updated January 20, 2013. Created by mlncn on February 9, 2011.
Edited by gisle, goron, jn2. Log in to edit this page.

Set Drupal to show all errors when developing your module. As an example of how this can help, if you are converting from D6 to D7, in hook forms you must replace the D6 $type = node_get_types('type', $node); with D7 $type = node_type_get_types($node);. The error is only reported when all PHP error reporting is switched on. Without the error reporting on, you get the dreaded White Screen of Death.

Change settings in your dev site

You can show all errors by adding a few lines to your local testing site's settings.php:

<?php
error_reporting
(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
?>

Note: Do not include the opening and closing PHP tags when you copy the code above. Those are already there in settings.php

In addition, navigate to Administration→ Configuration→ Development → logging and errors and select "All messages". (This sets $conf['error_level'] = 2; .)

Switch on strict PHP error reporting

Or you can go through your development site's php.ini file, in the php folder, and switch all error reporting on. To do this, check through your php.ini file and set error reporting to E_ALL | E_STRICT. The documentation there is very thorough, and you may find a different setting that's better suited to your needs. Warning: as the PHP documentation states, this setting is only for development sites, not for production sites.

Possible duplicate

http://drupal.org/node/158043

Comments

Code confusing for very novices

I do belong to that very novice category so I wanted to point out you should better drop the <?php and ?> tags because <?php has already been opened in the beginning of the settings.php file and ?> is not necessary. This may all seem very very trivial but these pages are not read by people who consider this so. The very very novices tumble over every rock.

I added a note in the page to

I added a note in the page to explain this

.

.

Remove those lines when pushing to production!

I just pushed my first drupal site to production. I went into the admin/config/development/logging page to hide the warnings/errors on the production site, but no matter how many times I changed the value to None and hit submit, it would always tell me the changes were Saved but the value was back to All Messages. It was because these lines of code were still in my settings and were overriding the value I set through the form.

I know it's mentioned in the last sentence of the article, but following these instructions on my first day as a newbie and then months later finally pushing to production... I had completely forgotten.

The reason is that the Input Filter used for these pages requires the “<?php … ?>” tags to demarcate a code segment that’s to be surrounded by a thin gray border on a light grayish background, with line endings respected (unlike with normal HTML), HTML tags and entities non-interpreted (since PHP and most other programming languages use “<” and “>” and “&” for other things), and with PHP syntax color-coded.

The only way to do it without those tags would be to use the “<code>…</code>” block instead, which does the other things but does not do the PHP syntax color-coding that would be so very helpful in such tutorials.

Proposed solution:

When doing a PHP code block and you do not want the user to copy the actual <?php … ?> tags, insert comments instructing the reader exactly where to begin and end copying, something like this:

<?php
// Do NOT copy the “<?php” above, nor these two comment lines!
// ↓START copying at the beginning of the NEXT BELOW↓!
error_reporting(-1);
$conf['error_level'] = 2;
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
// STOP copying at the END of the LINE JUST ABOVE↑!
// Do NOT copy the “?›” tag below, nor these two comment lines!
?>

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 7.x
Audience
Programmers
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.