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

| Published Date: 11 Sep 2014 | Last Updated Date: 04 Sep 2017
Total Reads: 4,382 | Last Visit: 21 Sep 2017 08:16:30 PM

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.

Solution

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

  1. <?php
  2. // at the end of the settings.php file, write this
  3. /* Fix notice error. Best config for production server */
  4. ini_set('error_reporting', 'E_ALL ^ E_NOTICE');
  5. ?>

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.

Tags

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
Max length 128 characters
Image CAPTCHA
Enter the characters shown in the image.

About This Mania

Hasan Hafiz, Blogger at web mania ltd (www.webemania.com). He has more than 5 years experience in web development platform. He worked as a Sr. Software Developer at Canadian based outsourcing software firm, Lead Developer at countries top most VOIPswitch development company and Sr. Software Engineer at USA based outsourcing software firm . His expertise areas are PHP, MySQL, CSS, Javascript, JQuery, HTML, XML and MVC Framework Codeigniter. He has been along with Drupal from more than 4 years. You may call him Drupal Addicted.