The following alternative method is used to write the following code. Question 1: The constructor is empty, and another alternative is that it is instantiated below, if the constructor is empty, how can we instantiate it?
Why?
'; // Request time $ trace [Language: get ('NC _ debug_request_time')] = date ('Y-m-d H: I: S ', $ _ SERVER ['request _ time']).'
'; // System running time $ query_time = number_format (microtime (true)-StartTime), 3 ).'s '; $ trace [Language: get ('NC _ debug_execution_time')] = $ query_time.'
'; // Memory $ trace [Language: get ('NC _ debug_memory_consumption')] = number_format (memory_get_usage ()/1024/1024, 2). 'mb '.'
'; // Request method $ trace [Language: get ('NC _ debug_request_method')] = $ _ SERVER ['request _ method'].'
'; // Communication PROTOCOL $ trace [Language: get ('NC _ debug_communication_protocol')] = $ _ SERVER ['server _ protocol'].'
'; // User agent $ trace [Language: get ('NC _ debug_user_agent')] = $ _ SERVER ['http _ USER_AGENT '].'
'; // Session ID $ trace [Language: get ('NC _ debug_session_id')] = session_id ().'
'; // Execution log $ Log = log: read (); $ trace [Language: get ('NC _ debug_logging')] = count ($ log )? Count ($ log). Language: get ('NC _ debug_logging_1 ').'
'. Implode ('
', $ Log): Language: get ('NC _ debug_logging_2'); $ trace [Language: get ('NC _ debug_logging ')] = $ trace [Language :: get ('NC _ debug_logging ')].'
'; // File loading $ files = get_included_files (); $ trace [Language: get ('NC _ debug_load_files')] = count ($ files ). str_replace ("\ n ",'
', Substr (print_r ($ files, true), 7), 0,-2 )).'
'; Return $ trace ;}}
Reply to discussion (solution)
This is a singleton mode.
The Singleton mode is a common software design mode. Its core structure only contains a special class called singleton class. The Singleton mode ensures that there is only one instance in a class in the system and the instance is easy to access, so as to conveniently control the number of instances and save system resources. If you want to have only one class object in the system, the singleton mode is the best solution.
Http://baike.baidu.com/view/1859857.htm
Whether the constructor is null is irrelevant to the instantiation.
The constructor is empty, but it indicates that no user-defined action is performed during instantiation. And do not execute the constructor of the parent class (if any ).
Private function _ construct (){}
Indicates that the class cannot be instantiated externally. private methods can only be accessed in the class that defines it.
New Tpl outside class
There will be a fatal error of Call to private Tpl ::__ construct () from invalid context
This is the singleton mode, but it is missing.
Private function _ clone (){}
If the object in Singleton mode can be cloned, it violates the original intention of Singleton.
For your class, not only is it meaningless, because all its attributes and methods are static.
Because static attributes are shared among instances