[drupal-devel] E_ALL: which way to correct each error notice?
Gabor Hojtsy
gabor at hojtsy.hu
Sat Oct 15 12:41:34 UTC 2005
> An example of the error notice we get is when going to
> admin/settings:
>
> notice: Undefined index: #attributes in
> includes/form.inc on line 54.
> notice: Undefined index: class in
> includes/form.inc on line 54.
>
> the line is part of:
> function drupal_get_form ($form_id,
> &$form, $callback = NULL)
> which is called in this case from system.module from
> function system_view_general()
>
> Now I can solve this problem in by declaring the array this
> way:
> $form['#attributes']['class'] = array ();
> I can add this line
> 1- either within the function drupal_get_form in
> includes/form.inc
> 2- or within the function system_view_general in
> modules/system.module.
>
> Which way would be better/correct?
Better is to check for the existance of the form item before using it,
not creating the item in every possible place. Since contributed code
can result in similar errors.
> Another similar example:
> notice: Undefined index: #built in
> includes/form.inc on line 180.
> should I change in the said line:
> if ($form['#built'] == TRUE) {
> to
> if (isset($form['#built']) AND $form['#built'] == TRUE) {
> or should I go back to where the function was called from,
> and declare the array there?
I don't know who have written "if ($form['#built'] == TRUE)", but AFAIK,
this is the very same as "if ($form['#built'])" (since it is casted to a
boolean either way. So shorter is to use "if (isset($form['#built']) &&
$form['#built'])"
Goba
More information about the drupal-devel
mailing list