Home  >  Article  >  Backend Development  >  LotusPhp Notes: Usage Analysis Based on ObjectUtil Component_PHP Tutorial

LotusPhp Notes: Usage Analysis Based on ObjectUtil Component_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:10:54781browse

The ObjectUtil component is actually the best example of the singleton mode. When calling each component, using ObjectUtil can effectively prevent errors or resource waste caused by calling too many classes.

For example, calling the Db component, just declare it like this

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

The singleton method is the only method in the LtObjectUtil class. The purpose is to declare the class library. If the class library has an init() method, then call the init() method of the class library.

ObjectUtil also has a quick call function that can be quickly called in the framework or template

has the following format:

C('LtDb');

In fact, it is LtObjectUtil::singleton('LtDb');

called inside the function

LotusPhp does not advocate excessive use of static classes. This is the only static class in the framework.

The pros and cons of static classes are not the topic today, but you can read this article Detailed explanation of the original sin based on PHP static classes>, that is, static classes, you can For reference.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327028.htmlTechArticleThe ObjectUtil component is actually the best example of the singleton mode. When declaring to call each component, use ObjectUtil to call it. Effectively prevent errors or resources caused by calling too many classes...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn