PHP preparations a large website problem set PHP is promoted quickly with its ease of use, but it is easy to say that it can be used, in fact, many programmers use it easy to set up a web application system, but how much People carefully consider their code, whether it is easy to maintain, whether it is strong enough, whether it is sufficiently safe, when PHP is used to establish large sites, these become a critical factor. Below we start discussing from a slight problem until some fatal errors. A total of three parts.
Part 1, slight mistake
First, Printf (), which is mainly used to format display data. Use when you want to change the display format of a data. For example, the value of PI (3.1415926) is displayed in different precursors. pHP / * * The Three Faces of π * /
Printf ("Pi IS:% .2F / N
/ N", M_PI); Printf ("Pi IS AlSo:% .3F / N
/ N", M_PI); Printf ("PI IS Also: % .4f / n
/ n ", m_pi);
However, many programmers use this function to display some variable values and functions. Because Printf () is pre-formatted before displaying the data, it is slower, so it is applied to the application of Print and ECHO only to increase the speed.
Second, the language checking PHP is a weak type of language, that is, do not use definition before using a variable, which brings a lot easier and flexible, but you must know which type of variable should be. Because the variable still actually corresponds to a certain type (between various types, there is no type of variable without types of variables. It is possible that PHP cannot check your language error, but due to variable type changes, there will be some potential problems. Another worthless problem is the range of variables, which may also cause some potential problems. There are several basic variables in PHP: Boolean, Resource, INTEGER, DOUBLE, STRING, ARRAY AND OBACT.
Third, the use of temporary variables will cause a reduction in program operation efficiency. When using temporary variables can be based on the following two points: 1, the variable is used at least twice. 2, whether the use of this variable will significantly improve the readability of the program. If an item is not satisfied, the use of the variable is omitted. For example: PHP $ TMP = Date ("F D, H: IA"); / * IE January 3, 2:30 PM * / Print $ TMP;?> It should be changed to: Php print Date (" F d, h: ia ");?>
Another example: PHP
// String Reverse_Characters (String Str) // Reverse All of the Characters in A String.Function Reverse_Characters ($ Str) {Return Implode ("", array_reverse (preg_split ("//", $ str));}
?> The readability is not strong, it can be changed: PHP
// string reverse_characters (string str) // Reverse all of the characters in a string.function reverse_characters ($ str) {$ characters = preg_split ( "//", $ str); $ characters = array_reverse ($ characters);
RETURN IMPLODE ("", $ taracters);}?>
4. The separation client and server-side code separation client and server-side code are actually HTML code and PHP language code in the PHP program. Many people mix HTML and PHP statements in a file, making this file very large. This style is very disadvantageous to the maintenance and renewal of the procedure and is not suitable for the development of large sites. There are usually two ways to separate HTML and PHP statements: 1. Write a dedicated API, for example: index.php? The client side Php incdude_once ("site.lib");>