How to fix Notice Undefined variable or Undefined index Problem In Drupal

September 09, 2014


The Problem

As we know, PHP is a loosely couple language. We can Use variable anywhere without declaring it. But in Drupal this produce an error message and each time we access any page this error is written to Drupal Watchdog table. So, If you see your Recent log entry page you will see lots of errors regarding this. A line of code can solve this !

It is best practice to turn off notice error in Production server.


Update your settings.php file inside /sites/default folder

// at the end of the settings.php file, write this
    /* Fix notice error. Best config for production server */
ini_set('error_reporting''E_ALL ^ E_NOTICE');

Now clear your Recent log entries. Browse your site and at the end of the days, you found no notice errors

Do not try

Do not try to put this above code any where else like your module page or inside function, because it won't work.