From a7dca139624ca900ef9868c20ea5f7dac0b5592d Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Wed, 21 Dec 2005 00:12:10 +0000 Subject: [PATCH] * File to aid in writing extensions, see documentation --- includes/PersistentObject.php | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 includes/PersistentObject.php diff --git a/includes/PersistentObject.php b/includes/PersistentObject.php new file mode 100644 index 0000000000..5c53acde30 --- /dev/null +++ b/includes/PersistentObject.php @@ -0,0 +1,51 @@ + + * class Extension { ... } + * function myExtension() { new Extension; } + * + * + * Won't work because PHP will destroy any reference to the initialized + * extension when the function goes out of scope, furthermore one might want to + * use some functions in the Extension class that won't exist by the time + * extensions get parsed which would mean lots of nasty workarounds to get + * around initialization and reference issues. + * + * This class allows one to write hir extension as: + * + * + * function myExtension() { + * class Extension { ... } + * new PersistentObject( new Extension ); + * } + * + * + * The class will then not get parsed until everything is properly initialized + * and references to it won't get destroyed meaning that it's possible to do + * something like: + * + * + * $wgParser->setHook( 'tag' , array( &$this, 'tagFunc' ) ); + * + * + * And have it work as expected + * + * @package MediaWiki + * @subpackage Extensions + * + * @author Ævar Arnfjörð Bjarmason + * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later + */ + +$wgPersistentObjects = array(); + +class PersistentObject { + function PersistentObject( &$obj ) { + $wgPersistentObjects[] = $obj; + } +} -- 2.20.1