Page MenuHomePhabricator

Calling User::getOption after User::setOption will return null instead of default values for an option if it isn't set
Closed, ResolvedPublic

Description

Assuming the following:
$user = new User;
$user->setOption( 'someoption' );
$user->getOption( 'someotheroption' );

the getOption will return null even though it is set in default options. When calling
$user->getOption( 'someotheroption' );
$user->setOption( 'someoption' );
instead, it will work perfectly fine.

This is because User::getOption() will check whether User::mOptions is set to null and in this case get the default options. It is not null anymore after setOption() though.
Therefore, the default options should be loaded in the constructor I guess. Might be that this is more expensive though. There could be a more complex solution to this, perhaps checking in setOption() whether options are null and then setting some internal member to check against in getOption()


Version: 1.20.x
Severity: normal

Details

Reference
bz37963

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 12:28 AM
bzimport set Reference to bz37963.
bzimport added a subscriber: Unknown Object (MLST).

Actually, both getOption() and setOption() call loadOptions(), which should be loading the default options into the object. However, it seems that loadOptions() refuses to work with anonymous users, which means the default options end up not getting loaded.

The only reason the second testcase (where you get and then set) even works is because getOption() has an additional check. The confusion here is because getOption() has an additional check (the if statement you see) that loads the default options.

I've prepared a fix for this and it is currently in review on Gerrit here: https://gerrit.wikimedia.org/r/17464