LotusPhp notes: usage analysis based on ObjectUtil components

  • 2020-06-01 08:57:51
  • OfStack

The ObjectUtil component is actually the best example of the singleton pattern. When calling various components, using ObjectUtil can effectively prevent calling too many classes and causing errors or resource waste.

Call the Db component, for example, and the declaration will do

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

The singleton method is the only one-of-a-kind method in the LtObjectUtil class. The purpose is to declare the class library, and if the class is stored in the init() method, then call the init() method of the class library.

ObjectUtil also has a quick call function that can be made in a framework or template

The format is as follows:



LotusPhp does not advocate using static classes too much. This is the only static class in the framework.

The pros and cons of static classes are not the topic of today, but you can look at this article < Original sin explanation based on PHP static class > The article, that is, the static class, can be used as a reference.

Related articles: