Last modified: 2010-05-15 15:56:56 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T8395, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 6395 - Empty object created by incorrect reference use in SpecialUserlogin.php
Empty object created by incorrect reference use in SpecialUserlogin.php
Product: MediaWiki
Classification: Unclassified
User login and signup (Other open bugs)
PC Linux
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
Depends on:
  Show dependency treegraph
Reported: 2006-06-21 16:17 UTC by Dave Challis
Modified: 2010-05-15 15:56 UTC (History)
0 users

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Description Dave Challis 2006-06-21 16:17:25 UTC
Line 307 in 'includes/SpecialUserlogin.php' is:
$u =& $this->initUser( $u );

The signature of the 'initUser' method on line 268 is:
function &initUser( &$u ) {
    return $u;

The combination of this use of references means that after calling '$u =&
$this->initUser( $u );', $u will always be an empty object.

Since 'initUser' is a method that takes a reference to a user object and
modifies it, there's no need for it to return anything at all, and there's no
need to assign its return value to the object it is modifying.

Some trivial php code which demonstrates the problem:
class user {
    var $name = 'Foo';

function &initUser(&$u) {
    $u->name = 'Bar';
    return $u;

$u = new User();
$u =& initUser($u);

The code above prints:
user Object
    [name] => Foo
user Object

Similarly, if you print the value of $u before and after line 307 of
SpecialUserlogin.php, you'll find same thing happens to it.
Comment 1 Brion Vibber 2006-06-21 17:02:36 UTC
Both PHP 4 (tested 4.4.1 and 4.4.3rc1) and PHP 5 (tested 5.1.2) show the expected 

user Object
    [name] => Foo
user Object
    [name] => Bar

If you get different results, you have a *buggy* version of PHP. Upgrade it.

Note You need to log in before you can comment on or make changes to this bug.