Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将类链接在一起_Php_Oop - Fatal编程技术网

Php 将类链接在一起

Php 将类链接在一起,php,oop,Php,Oop,我正在创建PHP应用程序,我对体系结构有疑问 我的应用程序中有一些系统。 例如,缓存系统、输出系统、应用系统等。 此外,我有注册表链接到这个系统在一起 以下是在应用程序中使用缓存的示例: 但这样我需要到处调用注册表,并且需要创建局部变量来存储对象 我有另一个想法,类似这样: class Kernel { public function __construct() { $this->JxCache = new JxCache; } } /* .. */ new

我正在创建PHP应用程序,我对体系结构有疑问

我的应用程序中有一些系统。 例如,缓存系统、输出系统、应用系统等。 此外,我有注册表链接到这个系统在一起

以下是在应用程序中使用缓存的示例:

但这样我需要到处调用注册表,并且需要创建局部变量来存储对象

我有另一个想法,类似这样:

class Kernel {
    public function __construct() {
        $this->JxCache = new JxCache;
    }
}
/* .. */
new Kernel();
/* .. */
class Manager extends Kernel {

    public function __construct() {

    }

    public function getAppInfo($JxId) {
        $someInfo = $this->JxCache->Applications->$JxId; //JxCache declared in class 'Kernel'
    }

}
哪个变体更正确? 你能推荐你的变体吗?
谢谢

Yii框架有一个不同的方法,您可能会喜欢它:


好的,我明白了。这是行为的唯一“ID”(?)。谢谢你,伊万,但我想要更多的变体…它们是标签,用来指代行为,例如删除。
class Kernel {
    public function __construct() {
        $this->JxCache = new JxCache;
    }
}
/* .. */
new Kernel();
/* .. */
class Manager extends Kernel {

    public function __construct() {

    }

    public function getAppInfo($JxId) {
        $someInfo = $this->JxCache->Applications->$JxId; //JxCache declared in class 'Kernel'
    }

}