title: Drupal FAPI Error; Cannot create references to/from string offsets nor overloaded objects
body: <p>I'm trying to add some custom autocomplete functionality to a couple text fields on my user registration page, along the lines of this tutorial; <a href="http://drupal.org/node/854216" rel="noreferrer">http://drupal.org/node/854216</a>.</p>
  
  <p>I've been able to successfully accomplish that, but now whenever I submit the registration form I get a blank page, and this error shows up in the log;</p>
  
  <blockquote>
    <p>PHP Fatal error:  Cannot create references to/from string offsets nor overloaded
    objects in /var/www/html/drupal/includes/common.inc on line 6448,
    referer: http://[...]/drupal/?q=user/register</p>
  </blockquote>
  
  <p>I can't find the topic now, but when I was initially googling this problem I read somewhere that this issue is typically that the '#' symbol has been added or missed from a property key. Because without a # symbol it treats the value of that property as a child, and thus an array. Or something along those lines, but after double checking it seems like all the properties I'm using should be as I've put them.</p>
  
  <p><strong>Here is the code, does anyone know what I'm doing wrong?</strong></p>
  
  <pre><code>function gtx_alterations_menu() {
    $items = array();
    $items['city/autocomplete'] = array(
      'page callback' =&gt; 'city_autocomplete',
      'access callback' =&gt; TRUE,
      'type' =&gt; MENU_CALLBACK
    );
    return $items;
  }
  
  function gtx_alterations_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    if ($form_id == 'user_register_form') {
      $form['field_city_of_residence']['#type'] = 'textfield';
      $form['field_city_of_residence']['#title'] = t('City of Residence');
      $form['field_city_of_residence']['#autocomplete_path'] = 'city/autocomplete';
      $form['field_headquarters_location']['#type'] = 'textfield';
      $form['field_headquarters_location']['#title'] = t('Headquarters Location');
      $form['field_headquarters_location']['#autocomplete_path'] = 'city/autocomplete';
    }
  }
  
  function city_autocomplete($string = '') {
    $cities = array();
    $locations = array();
    $results = file_get_contents('http://graph.facebook.com/search?q='.urlencode($string).'&amp;type=adcity');
  
    $results = preg_replace('/\\\\u0*([0-9a-fA-F]{1,5})/', '&amp;#x\1;', $results);
  
    preg_match_all('/"name":"[^,]+/', $results, $cities);
    preg_match_all('/"subtext":".+?,[^"]+/', $results, $locations);
  
    $final = array();
  
    foreach ($cities[0] as $key =&gt; $value) {
      $value = substr($value, 8);
      $subtext = substr($locations[0][$key], 11);
      $result = $value . ', ' . $subtext;
  
      $final[$result] = $result;
    }
  
    drupal_json_output($final);
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Some things I tried</strong></p>
  
  <p>When trying to narrow down the problem I determined that commenting out these two lines;</p>
  
  <pre><code>$form['field_city_of_residence']['#autocomplete_path'] = 'city/autocomplete';
  $form['field_headquarters_location']['#autocomplete_path'] = 'city/autocomplete';
  </code></pre>
  
  <p>removes the error, however that naturally means the autocomplete is also disabled.</p>
  
  <hr>
  
  <p>Additionally replacing the contents of city_autocomplete($string) with</p>
  
  <pre><code>drupal_json_output(array('test' =&gt; 'test'));
  </code></pre>
  
  <p>does not resolve the error, meaning that the problem isn't something in the that function.</p>
  
  <hr>
  
  <p>Removing the # symbol from these two lines</p>
  
  <pre><code>$form['field_city_of_residence']['#autocomplete_path'] = 'city/autocomplete';
  $form['field_headquarters_location']['#autocomplete_path'] = 'city/autocomplete';
  </code></pre>
  
  <p>causes the previous error to be replaced with this one,</p>
  
  <pre><code>Unsupported operand types in /var/www/html/drupal/includes/form.inc on line 1755
  </code></pre>