Notice: Object of class stdClass could not be converted to int in drupal_write_record() I'm building a new Drupal 7 and brought over the user table at the beginning of the project from another Drupal 7 site. All has been good with that except that when users save their profile, they get the following error, which I believe is related to our custom Avatar builder module. I am wondering what I can do to suspend the error message so that it doesn't show for now during our testing phase.


  Notice: Object of class stdClass could not be converted to int in
  drupal_write_record() (line 7340


Here is the section of code from the .module that I believe that relates to this error:

/**
 * Implements hook_user_insert().
 */
function my_avatar_selection_user_insert(&amp;$edit, $account, $category) {
  if (isset($account-&gt;picture)) {  
    $usage = new stdClass;
    $usage-&gt;uid = $account-&gt;uid;
    $usage-&gt;fid = $account-&gt;picture;
    drupal_write_record('my_avatar_selection_usage', $usage);
  }
}

/**
 * Implements hook_user_update().
 */
function my_avatar_selection_user_update(&amp;$edit, $account, $category) {  
  if (isset($account-&gt;picture)) {  
    $usage = new stdClass;
    $usage-&gt;uid = $account-&gt;uid;
    $usage-&gt;fid = $account-&gt;picture;
    $has_rows = (bool) db_query_range('SELECT 1 FROM {my_avatar_selection_usage} WHERE uid = :uid', 0, 1, array(':uid' =&gt; $account-&gt;uid))-&gt;fetchField();
    if ($has_rows) {
      drupal_write_record('my_avatar_selection_usage', $usage, 'uid');
    }
    else {
      drupal_write_record('my_avatar_selection_usage', $usage);
    }
  }
}


The module works by saving the data from jcarousel into the data field of the user table and when the profile is saved, it creates a graphic that looks like the options the users selected. As far as I can tell, there are no issues with saving the avatar, it just generates this error. I took this module from the old website 7.50 so maybe there is a component I don't need on the new site 7.54.
The error is caused from the fact $account-&gt;picture is an object, and drupal_write_record() is trying to convert it to an integer, since the my_avatar_selection_usage defines fid as an integer value. See the following code used from user_save(), which the function invoking hook_user_insert().

  // Process picture uploads.
  if (!empty($account-&gt;picture-&gt;fid) &amp;&amp; (!isset($account-&gt;original-&gt;picture-&gt;fid) || $account-&gt;picture-&gt;fid != $account-&gt;original-&gt;picture-&gt;fid)) {
    $picture = $account-&gt;picture;

    // Omissis

  }


As you see from that code, the correct code you should be using is the following one.

/**
 * Implements hook_user_insert().
 */
function my_avatar_selection_user_insert(&amp;$edit, $account, $category) {
  if (isset($account-&gt;picture)) {  
    $usage = new stdClass;
    $usage-&gt;uid = $account-&gt;uid;
    $usage-&gt;fid = $account-&gt;picture-&gt;fid;
    drupal_write_record('my_avatar_selection_usage', $usage);
  }
}

/**
 * Implements hook_user_update().
 */
function my_avatar_selection_user_update(&amp;$edit, $account, $category) {  
  if (isset($account-&gt;picture)) {  
    $usage = new stdClass;
    $usage-&gt;uid = $account-&gt;uid;
    $usage-&gt;fid = $account-&gt;picture-&gt;fid;
    $has_rows = (bool) db_query_range('SELECT 1 FROM {my_avatar_selection_usage} WHERE uid = :uid', 0, 1, array(':uid' =&gt; $account-&gt;uid))-&gt;fetchField();
    if ($has_rows) {
      drupal_write_record('my_avatar_selection_usage', $usage, 'uid');
    }
    else {
      drupal_write_record('my_avatar_selection_usage', $usage);
    }
  }
}