Code review!
[lhc/web/wiklou.git] / includes / PersistentObject.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die();
4 /**
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:
7 * <code>
8 * class Extension { ... }
9 * function myExtension() { new Extension; }
10 * </class>
11 *
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.
17 *
18 * This class allows one to write hir extension as:
19 *
20 * <code>
21 * function myExtension() {
22 * class Extension { ... }
23 * new PersistentObject( new Extension );
24 * }
25 * </code>
26 *
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
29 * something like:
30 *
31 * <code>
32 * $wgParser->setHook( 'tag' , array( &$this, 'tagFunc' ) );
33 * </code>
34 *
35 * And have it work as expected
36 *
37 * @package MediaWiki
38 * @subpackage Extensions
39 *
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
43 */
44
45 $wgPersistentObjects = array();
46
47 class PersistentObject {
48 function PersistentObject( &$obj ) {
49 $wgPersistentObjects[] = $obj;
50 }
51 }