Heim  >  Artikel  >  Backend-Entwicklung  >  LotusPhp笔记之:基于ObjectUtil组件的使用分析_PHP教程

LotusPhp笔记之:基于ObjectUtil组件的使用分析_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:10:54780Durchsuche

ObjectUtil组件其实就是单例模式的最好范例,声明调用各个组件的时候,用ObjectUtil调用,可以有效的防止调用过多的类而导致错误或者资源浪费。

比如调用Db组件,这样声明就可以了

$db = LtObjectUtil::singleton('LtDb');

singleton方法是LtObjectUtil类中唯一的方法,目的就是声明类库,如果该类库存在init()方法,然后调用该类库的init()的方法。

ObjectUtil 还有一个快速调用的函数,可以在框架里或者模板里进行快速调用

格式如下:

C('LtDb');

其实就是函数内部调用的LtObjectUtil::singleton('LtDb');

LotusPhp 是不太主张过多的使用静态类的,这个是框架中唯一的静态类。

对于静态类的优劣,不是今天说的主题,不过大家可以看看这篇基于PHP静态类的原罪详解>的文章,就是说静态类的,可以作为参考。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/327028.htmlTechArticleObjectUtil组件其实就是单例模式的最好范例,声明调用各个组件的时候,用ObjectUtil调用,可以有效的防止调用过多的类而导致错误或者资源...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn