Performance hacks to avoid killing the slaves;
[lhc/web/wiklou.git] / includes / PersistentObject.php
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>
9 *
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.
15 *
16 * This class allows one to write hir extension as:
17 *
18 * <code>
19 * function myExtension() {
20 * class Extension { ... }
21 * new PersistentObject( new Extension );
22 * }
23 * </code>
24 *
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:
28 *
29 * <code>
30 * $wgParser->setHook( 'tag' , array( &$this, 'tagFunc' ) );
31 * </code>
32 *
33 * And have it work as expected
34 *
35 * @package MediaWiki
36 * @subpackage Extensions
37 *
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
41 */
42
43 $wgPersistentObjects = array();
44
45 class PersistentObject {
46 function PersistentObject( &$obj ) {
47 $wgPersistentObjects[] = $obj;
48 }
49 }
50 ?>