0

I'm trying to create a form element with an array of child inputs. How is the below example incorrect in D7, I'm getting this error:

Fatal error: Cannot create references to/from string offsets nor overloaded objects in C:\wamp\www\water-uk\www\includes\common.inc on line 6518

array(3) {
  '#tree' =>
  bool(true)
  '#type' =>
  string(8) "fieldset"
  'first' =>
  array(6) {
    '#type' =>
    string(6) "select"
    '#options' =>
    array(8) {
      'All' =>
      string(8) "Show all"
      [0] =>
      class stdClass#470 (1) {
        ...
      }
      [1] =>
      class stdClass#468 (1) {
        ...
      }
      [2] =>
      class stdClass#469 (1) {
        ...
      }
    }
    '#size' =>
    NULL
    '#default_value' =>
    string(3) "All"
    '#ajax' =>
    array(5) {
      'callback' =>
      string(38) "_listing_blocks_select_tax_depth_js"
      'wrapper' =>
      string(18) "tax-select-wrapper"
      'method' =>
      string(6) "append"
      'effect' =>
      string(4) "fade"
      'event' =>
      string(6) "change"
    }
    '#required' =>
    bool(false)
  }
}

1 Answer 1

1

You appear to be using stdClass objects for the values in your options array. Drupal expects a string for each of the options.

You probably have code like:

foreach ($something as $item) {
  // $item is a stdClass.
  $options[$item->key] = $item;
}

when you need to have something like

foreach ($something as $item) {
  // $item is a stdClass.
  $options[$item->key] = $item->name;
}
2
  • This is a views exposed form, and it is how the form is generated initially, it seems happy with the objects. BTW I have with standard key value pairs and have the same issue.
    – kalpaitch
    Commented Jan 24, 2013 at 11:00
  • 1
    Gotcha. chx himself says the error is due to a missing # key somewhere, I'd check for that next
    – Clive
    Commented Jan 24, 2013 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.