Notice: Undefined index: XXX in include() (line XXX of XXX).

Error Type: 
PHP
Severity: 
Significant
Origin: 
watchdog
Description: 

This message is generated by the PHP runtime environment. It is identified as a "Notice" which means that something less than ideal is happening but it shouldn't stop your pages from loading.

However, it does deserve attention because this type of message indicates that you are at higher risk of suffering from logic errors. This means that the data you are presenting to your users might not be the data you are intending to display to your users.

Cause: 

The message "undefined index" tends to suggest that in your PHP code you have a variable that is an array. You have attempted to access a value in that array, but the array index you used is non-existent.

We frequently see this where developers are iterating over an array with a for loop and they iterate once too often, moving past the end of the array.

Solution: 

The error message in your watchdog log gives you nearly all of the information required to stop this error message showing up. Open the file that has been referenced and go to the line number given.

You should be able to see the code that is attempting to reference the array that is being accessed with an undefined index. Most of the time the solution will leap out of the page at you but if your code is more complex you may find it easier to track down the error condition by firing up an interactive debugging session and stepping through the code until you can see exactly why the invalid index is being used.

You should take care to ensure that any fixes are applied in the right place. For example is the problem with the code that references the array, or did an invalid value get passed into the enclosing function earlier on in the code execution.

It is also worth noting that if you find this error message refers to a core Drupal script then care must be taken not to break your upgrade path. As a golden rule, core scripts should not be edited. So if the source of the problem really is in the core script a patch should be created that can be submitted to Drupal so that the issue can be fixed in source.

Expedite

Our aim is to add enough detailed information to each of the Drupal error messages that Drupal developers will be able to fix their own problems. This exercise will take some time to complete, at the last count we had almost 700 error messages in the system.

If your site is suffering from this error message please contact us and ask us to expedite the solution to this error and we will do our best to add a solution as soon as possible.