Several notes for using PHP constants. Why be careful when using constants in PHP? The ZendFramework document states that a constant contains numbers, letters, and underscores. a number can be used as a constant name. All the letters of the constant name must be large. why should we be careful when using constants in PHP?
The Zend Framework document states that a constant contains numbers, letters, and underscores. a number can be used as a constant name. All letters of the constant name must be capitalized. A class constant must be defined as a member of a class through "const". it is strongly discouraged to use a global constant defined by "define.
As the official PHP framework, why is there such a requirement?
Let's analyze it together.
1. define is prone to unexpected errors.
PHP constants cannot be modified or assigned again after they are defined. But what if I assign a value again?
This code will report a notice error. The consequence is that, before you define a constant with the same name, you may not know what the value is.
2. how can I determine whether PHP constants are defined? Easy to write wrong judgment methods
3. low execution efficiency
Display ('/'. FORUM_THEME. '@ Public: login'); // The system searches for FORUM_THEME from the execution process.
Because php performs multiple searches when processing constants, the efficiency is low.
Summary: The problem with PHP constants lies in the fact that PHP is too loose in dealing with constants. if it can be strict, it will avoid many problems. In the actual process, you can use variables instead of constants, because the efficiency of variables is more convenient to use.
Therefore, if you do not want to use constants or class variables, you can use the following methods:
_forum_theme = $forum['theme']; } function displace() { echo $this->_forum_theme; } }?>
Function name
In PHP 4, the class constructor must be the same as the class name. The constructor name of the subclass is the same as that of the subclass. in the subclass, the constructor of the parent class is not executed automatically. To execute the constructor of the parent class in the subclass, you must execute statements similar to the following:
$ This-> [constructor name of the parent class ()]
In PHP 5.0 and later versions, construct () is used as the constructor, but it is still compatible with the definition rules of constructor 4.0. If both construct 4.0 and construct () are defined, the construct () function takes precedence.
Use php eol to replace/r/n for line feed
Line breaks are often used when writing a program, and the PHP built-in constant PHP_EOL is used for line breaks.
A small line feed has different implementations on different platforms. In the unix world, the newline is replaced by \ n, but in windows, \ r \ n is used to reflect its differences. What's more interesting is that \ r is used in mac. Therefore, \ n is used for unix, \ r \ n for windows, and \ r for mac.
Therefore, the system will convert to different line breaks based on different platform systems. Use the PHP_EOL variable to wrap a line in the browser.
Why? The Zend Framework document states that a constant contains numbers, letters, and underscores. a number can be used as a constant name. All letters of the constant name must be large...