Cannot use object of type stdClass as array error in node save I built a custom form and one of them is of  type geocode with lat/lon fields. When I try to save the node I receive the following error: 


  Cannot use object of type stdClass as array in
  /var/www/vhosts/example.com/httpdocs/modules/field/field.attach.inc on
  line 208\n'.


The error disappears when I put comments in this field. My question is how can I solve this since it is very important field (I try to create nodes with geocode locations)

Here is how I declare my field: 

$form['field_locationmap'] = array(
    '#title' =&gt; 'geofield',
    '#type' =&gt; 'geofield_latlon',
  );


It seems that the error occurs when I m trying to pass the values to the object:

$location-&gt;field_locationmap-&gt;und-&gt;{0}-&gt;geom-&gt;lon=$form_state['values']['field_locationmap']['lon'];
$location-&gt;field_locationmap-&gt;und-&gt;{0}-&gt;geom-&gt;lat=$form_state['values']['field_locationmap']['lat'];
Assuming this is Drupal 7 field_locationmap is an array so your assignment should look something like this:

$location-&gt;field_locationmap['und'][0]['geom']['lat']


Also make sure that['geom']['lat'] is the correct structure for that value (i.e it is an array with two keys)
P.S. Consider using $location->language instead of 'und' in case you support multiple languages.