Page MenuHomePhabricator

StubObject cannot forward call which expect a reference
Closed, ResolvedPublic


An example is the first test failure in $wgAuth->getUserInstance( $this ) is called somewhere in User, $wgAuth gets unstubbed, StubObject::_call calls call_user_func_array( [ <real AuthPlugin object>, 'getUserInstance' ], $user ) which explodes because the signature of that method is getUserInstance( User &$user ) and a plain object is passed.

Event Timeline

Tgr created this task.Apr 12 2016, 3:00 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptApr 12 2016, 3:00 PM
bd808 reopened this task as Open.Apr 12 2016, 3:18 PM
bd808 added a subscriber: bd808.

The fix in T78427: Pass-by-reference arguments not passed by reference through StubObject::_call() was a one off correction for Language::findVariantLink(). This looks to be another instance of the same underlying problem, namely that __call() magic doesn't support detecting pass-by-reference on the unstubbed object. There is no general solution to this class of problems. Either the stubbed object's method needs to change to not expect pass-by-reference input or an explicit method must be added to StubObject that preserves the expected method signature.

Anomie added a subscriber: Anomie.Apr 12 2016, 3:35 PM

Or the caller could pass the possibly-stub global through StubObject::unstub() before calling the method.

Tgr added a comment.Apr 12 2016, 3:43 PM

Well, the general solution is to use reflection to detect which arguments need to be references. But I imagine for something as performance-sensitive as unstubbing that would be a bad idea.

I doubt reflection would necessarily work right, anyway: the $args array passed to __call() probably doesn't have references in the first place, so even if we change things in there to references they won't be referencing what they should be referencing in the caller's scope.

Tgr added a comment.Apr 12 2016, 3:54 PM

Anomie fixed this in which removes the only place where AuthPlugin is stubbed.

Tgr closed this task as Resolved.Apr 12 2016, 5:41 PM
Tgr claimed this task.