Show all errors while developing

  • You want to know about every error when developing- so you know when something isn't right even when everything seems to be working fine, and even more when things go wrong.

    The below code goes in settings.php (minus the opening and closing php tags; settings.php will already have opened PHP at the top of the file and you should not close PHP at the end of a document.

    (-1);  // Have PHP complain about absolutely everything.
    $conf['error_level'] = 2// Show all messages on your screen
    ini_set('display_errors', TRUE);  // These lines give you content on WSOD pages.
    ini_set('display_startup_errors', TRUE);

    Note that for the error_level configuration setting above 2 = ERROR_REPORTING_DISPLAY_ALL but that constant is not loaded yet, so we have to use the number 2.

    Originally inspired by and posted to Randy Fay's blog post, If you edit PHP code, please work with E_NOTICE turned on!!!.

    Note As noted, the configuration 'error_level' sets what level of warning and error messages are sent to the screen. As a general principle, though, how do you know what configuration variables are available for overriding in settings.php? You can see what values are presently in the variable table with debug($conf); in your code. However, variables which have never had their settings form saved – which are still at their default value – will not show up in the table or the $conf array. Instead, the fastest way to determine the names of these is to debug output on a settings page you are interested in. Visiting Administration » Configuration » Development » Logging and errors (admin/config/development/logging) while an implementation of hook_form_alter() such as this one while example module was active:

    function example_form_alter(&$form, &$form_state, $form_id) {
    debug($form, $form_id);

    would enable you to identify the 'error_level' configuration variable.