1. The difference between a single quote and a double quote
A string is typically identified by single or double quotation marks. The single quote string and the double quote string are handled differently in PHP. The contents of the double quotation mark can be interpreted and replaced, and the contents of the single quotation mark string are treated as ordinary characters.
For example:
$STR = 6;
echo "STR is $STR \ n";
Echo ' str is $STR \ n ';
Note: The output in single quotation marks is "WYSIWYG", whether or not variable, is output as normal character.
Description: When defining a simple string, using single quotes is a more appropriate way to handle it. If you use double quotes, PHP will take the time to handle the escape of the string and parse the variables. Therefore, it is recommended that you use single quotes whenever possible when defining a string, if there is no special requirement.
2. Notice the difference between Echo and print
Both Echo and print in PHP are output, but there are subtle differences between the two. There is no return value after the echo output, but print has a return value and returns Flase when its execution fails. So it can be used as a normal function, for example, "= print" Hello world "; The value of the variable will be 1. And the Echo statement in the code runs faster than the print statement.
3. Note the difference between the empty string (' ') and null
PHP hollow strings and null are stored with a value of 0, but their type is not the same, the former is a string, while the latter is null, the visible string ("'), the null value is equal but the type is unequal.
4. Distinguish between = = (equals) and = = = (all equals)
Both are comparison operators, = = (equals) Only compare values for equality, and = = = (all equals) not only compare the values are equal, but also compare the type is equal, it is more strict.
5. Distinguish self:: the difference from this->
When accessing a member variable or method in a PHP class, if the referenced variable or method is declared as a const (constant) or static property, then the domain operator must be used::, and if the referenced variable or method is not declared as const or static, Then use the pointer to operator.
The difference between 6.require and include
There are two ways to refer to a file: Require and include. Two ways to provide different use elasticity.
Require use methods such as require ("myrequirefile.php");. This function is usually placed at the front of the PHP program, and before the PHP program executes, it is read into the file specified by require to make it a part of the PHP program's Web page. Commonly used functions, you can also use this method to introduce it into the Web page.
Include usage methods such as include ("myincludefile.php");. This function is usually placed in the processing part of the process control. The PHP Program page reads the include file before it is read in. This way, you can simplify the process when the program executes.
The two of them are used exactly the same, not necessarily which one is in the front and the other in the middle. Their most fundamental difference is that they are not handled in the same way.
Require a file is wrong, then the program will break execution and display a fatal error
Include a file if there is an error, then the program will not be the middle end, but continue to execute, and display a warning error.
The following supplements are:
(1). Include has a return value, and require does not.
(2). Include () includes and runs the specified file when processing fails the include () generates a warning that the imported program code will be executed, and that the program will execute with the same range of variables as the location of the call to the include () statement in the source file. You can import static pages from the same server.
(3). The role of Include_once () and the include () are almost identical
The only difference is that include_once () will first check if the file to be imported has been imported elsewhere in the program, and if it does not repeat the import again (this feature is sometimes important, for example, to import a declaration of some functions that you define yourself, If you import this file repeatedly in the same program, an error message will occur on the second import because PHP does not allow the same name function to be repeated for the second time.
(4). require () reads the contents of the target file and replaces itself with the read-in content that require () causes a fatal error when processing fails.
This read-and-replace action occurs when the PHP engine compiles your program code, not when the PHP engine starts to execute the compiled program code (the PHP 3.0 engine works by compiling a line, but changes after PHP 4.0, PHP 4.0 is the entire program code to complete the compilation, and then the compiled program code once executed, in the process of compiling will not execute any program code). Require () is typically used to import static content, while the include () is suitable for importing dynamic program code.
(5). Like Include_once (), require_once () checks whether the contents of the target file have been imported before, and if so, does not re-import the same content again.
(6). Require is an unconditional inclusion, that is, if a process joins require, the require will be executed first, whether the condition is established or not.
(7). Require is usually placed at the front of the PHP program, and before the PHP program executes, it is read into the file specified by require to make it a part of the PHP program's Web page. Commonly used functions, you can also use this method to introduce it into the Web page.
(8). Include is generally placed in the Process Control section of the PHP Program page when reading the include file, it will be read in. This way you can simplify the process of executing the program.
Some of PHP's easy-to-wrong points