2 if ( ! defined( 'MEDIAWIKI' ) )
5 * Sometimes one wants to make an extension that defines a class that one wants
6 * to backreference somewhere else in the code, doing something like:
8 * class Extension { ... }
9 * function myExtension() { new Extension; }
12 * Won't work because PHP will destroy any reference to the initialized
13 * extension when the function goes out of scope, furthermore one might want to
14 * use some functions in the Extension class that won't exist by the time
15 * extensions get parsed which would mean lots of nasty workarounds to get
16 * around initialization and reference issues.
18 * This class allows one to write hir extension as:
21 * function myExtension() {
22 * class Extension { ... }
23 * new PersistentObject( new Extension );
27 * The class will then not get parsed until everything is properly initialized
28 * and references to it won't get destroyed meaning that it's possible to do
32 * $wgParser->setHook( 'tag' , array( &$this, 'tagFunc' ) );
35 * And have it work as expected
38 * @subpackage Extensions
40 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
41 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
42 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
45 $wgPersistentObjects = array();
47 class PersistentObject
{
48 function PersistentObject( &$obj ) {
49 $wgPersistentObjects[] = $obj;