MediaWiki  1.23.14
StubObject Class Reference

Class to implement stub globals, which are globals that delay loading the their associated module code by deferring initialisation until the first method call. More...

Inheritance diagram for StubObject:

Public Member Functions

 __call ( $name, $args)
 Function called by PHP if no function with that name exists in this object. More...
 
 __construct ( $global=null, $class=null, $params=array())
 Constructor. More...
 
 _call ( $name, $args)
 Function called if any function exists with that name in this object. More...
 
 _newObject ()
 Create a new object to replace this stub object. More...
 
 _unstub ( $name='_unstub', $level=2)
 This function creates a new object of the real class and replace it in the global variable. More...
 

Static Public Member Functions

static isRealObject ( $obj)
 Returns a bool value whenever $obj is a stub object. More...
 
static unstub ( $obj)
 Unstubs an object, if it is a stub object. More...
 

Public Attributes

 $mClass
 
 $mGlobal
 
 $mParams
 

Detailed Description

Class to implement stub globals, which are globals that delay loading the 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 another function, and the other function calls some method of the stub. The best way to avoid this is to make constructors as lightweight as possible, deferring any initialisation which depends on other modules. As a last resort, you can use StubObject::isRealObject() to break the loop, but as a general rule, the stub object mechanism should be transparent, and code which refers to it should be kept to a minimum.

Definition at line 44 of file StubObject.php.

Constructor & Destructor Documentation

◆ __construct()

StubObject::__construct (   $global = null,
  $class = null,
  $params = array() 
)

Constructor.

Parameters
string$globalname of the global variable.
string$classname of the class of the real object.
array$paramsparameters to pass to constructor of the real object.

Reimplemented in DeprecatedGlobal.

Definition at line 55 of file StubObject.php.

References $params.

Member Function Documentation

◆ __call()

StubObject::__call (   $name,
  $args 
)

Function called by PHP if no function with that name exists in this object.

Parameters
string$namename of the function called
array$argsarguments
Returns
mixed

Reimplemented in StubUserLang, and StubContLang.

Definition at line 118 of file StubObject.php.

References $args, $name, and _call().

◆ _call()

StubObject::_call (   $name,
  $args 
)

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 self::__call() function and that function will call this function. This function will also call the function with the same name in the real object.

Parameters
string$namename of the function called
array$argsarguments
Returns
mixed

Definition at line 97 of file StubObject.php.

References $args, $GLOBALS, $name, _unstub(), and array().

Referenced by __call(), StubContLang\__call(), and StubUserLang\__call().

◆ _newObject()

StubObject::_newObject ( )

Create a new object to replace this stub object.

Returns
object

Reimplemented in StubUserLang, StubContLang, and DeprecatedGlobal.

Definition at line 106 of file StubObject.php.

References MWFunction\newObj().

Referenced by _unstub().

◆ _unstub()

StubObject::_unstub (   $name = '_unstub',
  $level = 2 
)

This function creates a new object of the real class and replace it in the global variable.

This is public, for the convenience of external callers wishing to access properties, e.g. eval.php

Parameters
string$namename of the method called in this object.
$levelInteger: level to go in the stack trace to get the function who called this function.
Exceptions
MWException

Definition at line 133 of file StubObject.php.

References $fname, $GLOBALS, $mGlobal, _newObject(), wfDebug(), wfGetCaller(), wfProfileIn(), and wfProfileOut().

Referenced by _call().

◆ isRealObject()

static StubObject::isRealObject (   $obj)
static

Returns a bool value whenever $obj is a stub object.

Can be used to break a infinite loop when unstubbing an object.

Parameters
$objObject to check.
Returns
Boolean: true if $obj is not an instance of StubObject class.

Definition at line 68 of file StubObject.php.

Referenced by ParserOptions\__construct().

◆ unstub()

static StubObject::unstub (   $obj)
static

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.

Parameters
$objObject to check.
Returns
void

Definition at line 80 of file StubObject.php.

Referenced by User\isHidden(), and User\isLocked().

Member Data Documentation

◆ $mClass

StubObject::$mClass

Definition at line 45 of file StubObject.php.

◆ $mGlobal

StubObject::$mGlobal

Definition at line 45 of file StubObject.php.

Referenced by _unstub().

◆ $mParams

StubObject::$mParams

Definition at line 45 of file StubObject.php.


The documentation for this class was generated from the following file: