//前面一个还是不完善的 这次完善了全局访问 <?php /** * 用数组形式存储对象 * @author wolf [Email: 116311316@qq.com] * @version 1.0 */ class Helper implements ArrayAccess, Countable { public $_helperName; //用于存储插件对象 public function __construct() { return $this->_helperName = array(); } public function offsetExists($offset) { return array_key_exists($offset, $this->_helperName); } public function offsetSet($offset, $value) { return $this->_helperName[$offset] = $value; } public function offsetGet($offset) { return $this->_helperName[$offset]; } public function offsetUnset($offset) { unset($this->_helperName[$offset]); } public function count() { } public function getPlugin() { return $this; } } /** * this is my plugin * @author wolf [Email: 116311316@qq.com] * */ class MyPlugin { public $_configs; public function __construct() { return $this->_configs = '这是个插件'; } public function preDispatch() { } } /** * myAction * @author wolf [Email: 116311316@qq.com] * */ class Action { public static $_stack = null; public static function getHelper() { return self::$_stack = new Helper(); } public static function addHelper($helper) { self::getHelper()->offsetSet('smarty', $helper); } public static function getPlugin() { return self::$_stack->offsetGet('213213'); } } //add your puglin Action::addHelper(new MyPlugin()); $savePlugin = Action::getPlugin(); print_r($savePlugin);