Last modified: 2012-11-03 18:18:48 UTC
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()
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