Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
jhodgdonOh 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:
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.