From 37ed022c25d715e9434557cb32d197afa41bfee5 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 11 Sep 2013 12:55:15 -0700 Subject: [PATCH] Add StubObject::unstub, and use it for $wgAuth->getUserInstance() PHP's __call magic method can't handle functions with reference parameters correctly,[1] which means that we need to manually unstub StubObjects before calling such a method. Or you could use call-time pass by reference with call_user_func_array, which is rather backwards and verbose. This change adds a convenience function to do this, and applies it to the two calls which brought it to my attention. [1]: https://bugs.php.net/bug.php?id=40694, https://bugs.php.net/bug.php?id=62455 Change-Id: I74a0c04bf358e164f753b82fbefbd6205d9b2451 --- includes/StubObject.php | 20 ++++++++++++++++++++ includes/User.php | 2 ++ 2 files changed, 22 insertions(+) diff --git a/includes/StubObject.php b/includes/StubObject.php index 59238faa90..a3970f34cb 100644 --- a/includes/StubObject.php +++ b/includes/StubObject.php @@ -25,6 +25,12 @@ * their associated module code by deferring initialisation until the first * method call. * + * Note on reference parameters: + * + * If the called method takes any parameters by reference, the __call magic + * here won't work correctly. The solution is to unstub the object before + * calling the method. + * * Note on unstub loops: * * Unstub loops (infinite recursion) sometimes occur when a constructor calls @@ -63,6 +69,20 @@ class StubObject { return is_object( $obj ) && !$obj instanceof StubObject; } + /** + * Unstubs an object, if it is a stub object. Can be used to break a + * infinite loop when unstubbing an object or to avoid reference parameter + * breakage. + * + * @param $obj Object to check. + * @return void + */ + static function unstub( $obj ) { + if ( $obj instanceof StubObject ) { + $obj->_unstub( 'unstub', 3 ); + } + } + /** * Function called if any function exists with that name in this object. * It is used to unstub the object. Only used internally, PHP will call diff --git a/includes/User.php b/includes/User.php index 560c5dcae7..60efc9d41e 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1700,6 +1700,7 @@ class User { return $this->mLocked; } global $wgAuth; + StubObject::unstub( $wgAuth ); $authUser = $wgAuth->getUserInstance( $this ); $this->mLocked = (bool)$authUser->isLocked(); return $this->mLocked; @@ -1717,6 +1718,7 @@ class User { $this->getBlockedStatus(); if ( !$this->mHideName ) { global $wgAuth; + StubObject::unstub( $wgAuth ); $authUser = $wgAuth->getUserInstance( $this ); $this->mHideName = (bool)$authUser->isHidden(); } -- 2.20.1