Search code examples
phpdrupal-7php-7.2

Drupal 7 custom form Cannot use string offset as an array error with php 7.2


I have a custom drupal 7 form as below

   $form['general_details'] = array(
         '#type' => 'fieldset',
         '#title' => t('General'),
         '#description' => t('General Information.'),
         '#required' => TRUE,
         );

   $form['general_details']['salutation'] = array(
         '#type' => 'select',....

I am getting an error in the line "$form['general_details']['salutation']" Error: Cannot use string offset as an array with PHP7.2

Can someone help ? Thanks in advance.


Solution

  • You must declare empty array before assign it

     $form = array();
    
    $form['general_details'] = array(
             '#type' => 'fieldset',
             '#title' => t('General'),
             '#description' => t('General Information.'),
             '#required' => TRUE,
    );
    
    $form['general_details']['salutation'] = array(
             '#type' => 'select',....