<?phpclass A //核心{ public $db; public function __construct(){ $this->db=new B(); } public function find(){ return $this->db->b1(); }}class B //数据库{ public function b1(){ return true; } public function b2(){ return false; }}//**********分隔符***********class C extends A //第三方类{ static function test(){ return self::find(); }}//当前文件if(C::test()){ echo 'OK'; }?>
虽然不符合规则,但也不是不可以
或许以后还会改变规则呢?自己给自己套枷锁总是没道理的
class A //核心{ private static $_Instance; public $db; public function __construct(){ $this->db=new B(); } public function find(){ if(empty(self::$_Instance)) self::$_Instance = new self(); return self::$_Instance->db->b1(); }}class B //数据库{ public function b1(){ return true; } public function b2(){ return false; }}//**********分隔符***********class C extends A //第三方类{ static function test(){ return self::find(); }}error_reporting(E_ALL ^ E_STRICT);//当前文件if(C::test()){ echo 'OK'; }
版主果然牛叉,果断收藏