Jump to content

Topic on Talk:Requests for comment/Unit testing

Bawolff (talkcontribs)

I think this might be slightly over-stating the problems globals cause. Well we should certainly try to decrease their presence, I don't think they're preventing newbies from contributing, or causing huge problems in developing mediawiki (although they might affect tests more than normal development).

Personally, I don't see that much of a difference between a global like $wgOut that is pretty much the only instance of its respective class and a static method to get an instance of the class to be used with the request ( RequestContext::getMain()->getOutput() or whatever)

(Of course things like $wgTitle is just evil and needs to die, but that goes without saying ;)

😂 (talkcontribs)

The problem with global state objects is that people can (and do) change them on a whim. By incapsulating them in accessors, you keep that sort of thing from happening and behavior is much more testable.

Krinkle (talkcontribs)

Here follows probably the worst and unlikely example.....

... consider a newbie creating a new extension and doing some temporary variable assignments before doing stuff:

$wgIn = array( 'Awesome' );

function wfMakeOut( $in ) {
  // Magic
  return $in;
}

$wgOut = wfMakeOut( $wgIn );
foreach( $wgOut as $out ) {
  $wgHooks['Foobar' . $out][] = 'wfMyFunc';
}


I know $wgOut isn't available yet in LocalSettings! like I said, bad example.

Reply to "globals"