persistentobject.php

来自「php 开发的内容管理系统」· PHP 代码 · 共 51 行

PHP
51
字号
<?php/** * Sometimes one wants to make an extension that defines a class that one wants * to backreference somewhere else in the code, doing something like: * <code> * class Extension { ... } * function myExtension() { new Extension; } * </class> * * 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: * * <code> * function myExtension() { *	class Extension { ... } *	new PersistentObject( new Extension ); * } * </code> * * 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: * * <code> * $wgParser->setHook( 'tag' , array( &$this, 'tagFunc' ) ); * </code> * * And have it work as expected * * @package MediaWiki * @subpackage Extensions * * @author 脝var Arnfj枚r冒 Bjarmason <avarab@gmail.com> * @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;	}}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?