0
Notice: Array to string conversion in update_results_page() (line 212 of /Users/timdaff/Sites/local-quest-skills-for-life/update.php).

I'm getting the above notice after running update.php on the update function for my module. It is a simple update to disable some modules I no longer require. I'm not a PHP guru and it appears to me I have everything correct.

/**
 * Disabling modules. Implements hook_update_N().
 */
function features_controller_update_6009() {
    $return = array();
    $modules = array('views_cache_bully');
    $modules[] = 'gauth';
    $modules[] = 'oauth_common';
    $modules[] = 'oauth2_common';
    module_disable($modules,TRUE);
    $return[] = array('success' => TRUE, 'query' => 'Disabling views_cache_bully, oauth, gauth, gauth_login');
    return $return;
}
1

Per the docs, the return value should be a string (the message to show to the user after the update) or null.

Currently you're returning an array, hence the notice.

| improve this answer | |
1

The return value you are using is the value hook_update_N() would return in Drupal 6. In fact, in Drupal 6 it was common to use code similar to the following one. (See locale_update_6000().)

$ret[] = update_sql("DROP TABLE {locales_meta}");

That is the only case where Drupal code actually populate the $ret value; in the other cases, it just returns an empty array.

function comment_update_6003() {
  $ret = array();
  db_add_index($ret, 'comments', 'pid', array('pid'));
  return $ret;
}

Drupal 7 is especting a string to be returned, or NULL; Drupal core code usually doesn't return a string. An exception is supposed to be raised in case of fatal errors.

function aggregator_update_7002() {
  db_add_field('aggregator_feed', 'queued', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'description' => 'Time when this feed was queued for refresh, 0 if not queued.',
  ));
  db_add_index('aggregator_feed', 'queued', array('queued'));
}

Keep in mind that Drupal 7 takes the update description from the comment placed on top of the hook itself; in most of the cases, that is sufficient.

| improve this answer | |
  • Thanks guys, I'm just returning a string now successfully. Yes I had found the comment above to be used, and now don't really see the point in returning a string if you can't specify whether it's a success message or an error. Why not just use the comment above entirely. – pi_ron Jan 12 '15 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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