The user_load_self method needs reworking. I've recently needed to use it and when I looked at the code (which is very simple) I saw that the method is very amateurishly written.

The main goal of the method is as I see it to get the current logged user. But instead of a user object I get an array(which I passed as an argument , why?) that has only one element the user object on the second position!

The code for the method is this:
function user_load_self($arg) {
$arg[1] = user_load($GLOBALS['user']->uid);
return $arg;
}

The code works fine if you just do this:
function user_load_self() {

return user_load('uid'=>array($GLOBALS['user']->uid));
}

Plus the method is totally undocumented.

Comments

damien tournoud’s picture

This function was introduced during the work on the D6 menu system. I think it does nothing and should simply be removed.

taps128’s picture

I do not agree with you. It gets the current registered user. I just needs refactoring.

mr.baileys’s picture

Title: user_load_self method needs rework » Remove user_load_self
Version: 6.4 » 7.x-dev
Status: Active » Needs review
Issue tags: +DX (Developer Experience)
StatusFileSize
new643 bytes

I agree with Damien, this has to go. I arrived here while trying to figure out what user_load_self is and where it's used, and so far it seems unused and a bit WTF-ish:

Some google finds about how this method is used:

$user = array_shift(user_load_self(array()));
$user = user_load_self($arg);
$user = $user[1];

If there is a genuine need for this function in core or contrib, then it should be documented (and refactored).

EDIT: fixed link.

Status: Needs review » Needs work
Issue tags: -DX (Developer Experience)

The last submitted patch, user_load_self_needs_to_go_away_or_be_documented.patch, failed testing.

mr.baileys’s picture

Status: Needs work » Needs review
Issue tags: +DX (Developer Experience)
dries’s picture

Status: Needs review » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)
Issue tags: -DX (Developer Experience)

Automatically closed -- issue fixed for 2 weeks with no activity.