function user_save($account, $array = array(), $category = 'account') {
  // Dynamically compose a SQL query:
  $user_fields = user_fields();
  if (is_object($account) && $account->uid) {

In that last line, it is quite likely (about half the time, actually) that $account->uid is not defined (which indicates it's a new user account rather than an update of an existing account).

In that case, you get a PHP notice on that line saying:
Undefined property: stdClass::$uid

I think the fix would be to change that line to:

if (is_object($account) && !empty($account->uid)) {

but I haven't yet tested it...

Comments

jhodgdon’s picture

Oh and by the way, I encountered this while running some Drupal 6 SimpleTest tests for one of my contrib modules. It's possible that in normal interactive use of a Drupal site that this wouldn't be encountered... and also you have to have your PHP notice level set to the strictest possible to see this.

In fact, I just tested adding a new user through the normal admin UI, and there was no problem. So it's probably at least partly an artifact of how SimpleTest is calling user_save(). However, the phpdoc for user_save does say:

 * @param $account
 *   The $user object for the user to modify or add. If $user->uid is
 *   omitted, a new user will be added.

Which does imply that $account->uid can be omitted. Wow, that PHP doc also needs to be fixed. I'll file a separate issue about that if it doesn't already exist.

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.