Remove obsolete hacks; Language.php no longer has to be loaded for Names.php
[mediawiki.git] / includes / PersistentObject.php
blob100752188b9ce58934dcccd6f4d1b67b605e71bb
1 <?php
2 /**
3 * Sometimes one wants to make an extension that defines a class that one wants
4 * to backreference somewhere else in the code, doing something like:
5 * <code>
6 * class Extension { ... }
7 * function myExtension() { new Extension; }
8 * </class>
10 * Won't work because PHP will destroy any reference to the initialized
11 * extension when the function goes out of scope, furthermore one might want to
12 * use some functions in the Extension class that won't exist by the time
13 * extensions get parsed which would mean lots of nasty workarounds to get
14 * around initialization and reference issues.
16 * This class allows one to write hir extension as:
18 * <code>
19 * function myExtension() {
20 * class Extension { ... }
21 * new PersistentObject( new Extension );
22 * }
23 * </code>
25 * The class will then not get parsed until everything is properly initialized
26 * and references to it won't get destroyed meaning that it's possible to do
27 * something like:
29 * <code>
30 * $wgParser->setHook( 'tag' , array( &$this, 'tagFunc' ) );
31 * </code>
33 * And have it work as expected
35 * @package MediaWiki
36 * @subpackage Extensions
38 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
39 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
40 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
43 $wgPersistentObjects = array();
45 class PersistentObject {
46 function PersistentObject( &$obj ) {
47 $wgPersistentObjects[] = $obj;