In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the problems that may be ignored in PHP. It is very detailed and has a certain reference value. Friends who are interested must finish reading it.
The difference between 1.echo and print
The functions of echo and print in PHP are basically the same (output), but there are slight differences between them. There is no return value after echo output, but print has a return value, which returns flase when its execution fails. So it can be used as a normal function, for example, the value of the variable $r will be 1 after executing the following code.
$r = print "Hello World"
This means that print can be used in some complex expressions, while echo is not. However, because the echo statement does not require any numeric values to be returned, the echo statement in the code runs slightly faster than the print statement.
The difference between 2.include and require
The functions of include () and require () are basically the same (inclusive), but there are some differences in usage. Include () is a conditional inclusion function, while require () is an unconditional inclusion function. For example, in the following code, if the variable $an is true, the file a.php is included:
If ($a) {
Include ("a.php")
}
Unlike include (), require (), no matter what the value of $a, the following code will include the file a.php in the file:
If ($a) {
Require ("a.php")
}
In terms of error handling, use the contains statement. If an error occurs, the program will skip the include statement, and the program will continue to execute even though the error message is displayed! But requre will make a fatal mistake for you.
Of course, literally, we can also understand seven points: requre is a very strong request, the meaning of request.
3.require_once () and include_once () statements
That's beside the point, because it looks like the simple require_once () and include_once () statements correspond to require () and include () statements, respectively. Require_once () and include_once () statements are mainly used when you need to include multiple files, which can effectively avoid the error of repeatedly defining functions or variables by including the same piece of code.
4. The difference between an empty string ('') and NULL
Both the empty string and NULL in PHP are stored with a value of 0, but their types are not the same. You can try echo gettype ('); and echo gettype (NULL); you will find that they print out string and NULL respectively. Of course, 0 is also easy to be confused. You can try echo gettype (0). If you print the type, you will find that the type of 0 is integer (integer), and the visible strings (''), NULL, and 0 are "equivalent" but not equal types.
The difference between 5.isset and empty
Literally, we can see that empty determines whether a variable is "empty", while isset determines whether a variable has been set. But there is one thing to be absolutely aware of here: when a variable with a value of 0 is considered empty, the variable is equivalent to null, which means it is not set. For example, when we detect the $id variable, when $id=0 uses empty and isset to detect whether the variable $id has been configured, both of them will return different values: empty thinks it is not configured, while isset can get the value of $id. See the following example:
$id=0
Empty ($id)? print "I am empty": print "I am $id."; / / result: I am empty
! isset ($id)? print "I am empty": print "I am $id."; / / result: I am 0
6. The difference between equal = (etc.) and = = (identity)
Reviewing the difference between the fourth empty string ("") above and NULL, let's look at another example:
'' = = NULL
'' = NULL
After running it, you will find that the first one is true and the second one is false! It can be seen that = = only compares whether the values are equal, while = = compares not only the values, but also the types, which is more stringent.
The difference between 7.self:: and this- >
When accessing member variables or methods in the PHP class, if the referenced variable or method is declared as const (define constant) or static (declare static), then you must use the operator::, whereas if the referenced variable or method is not declared as const or static, then you must use the operator->.
In addition, if you access a const or static variable or method from within the class, you must use the self-referenced self, whereas if the internal access from the class is not a const or static variable or method, you must use the self-referenced $this.
The difference between 8.strstr () and strpos ()
Stristr () is case-insensitive strstr () is case-sensitive
Function to find the first occurrence of a string in another string.
If successful, the rest of the string is returned (from the match point). If the string is not found, false is returned.
Stripos () is case-insensitive strpos () is case-sensitive
Function returns the position where the string first appears in another string.
If the string is not found, false is returned.
It is proved that the execution efficiency of strpos () is greater than that of strstr () if it is just to find and judge whether it exists or not.
HTTP_HOST and SERVER_NAME in 9.PHP
Similarities:
Both output the same information when the following three conditions are met.
1. The server is port 80
2. ServerName is set correctly in conf of apache
3. HTTP/1.1 protocol specification
Differences:
1. In general:
_ SERVER ["HTTP_HOST"] under the HTTP/1.1 protocol specification, the information is output according to the HTTP request of the client.
_ SERVER ["SERVER_NAME"] outputs the ServerName value in apache's configuration file httpd.conf directly by default.
two。 When the server is a non-80 port:
_ SERVER ["HTTP_HOST"] outputs the port number, for example: mimiz.cn:8080
_ SERVER ["SERVER_NAME"] outputs the ServerName value directly
Therefore, in this case, it can be understood as: HTTP_HOST = SERVER_NAME: SERVER_PORT
3. When the ServerName in the configuration file httpd.conf is inconsistent with the domain name requested by HTTP/1.0:
The httpd.conf configuration is as follows:
ServerName mimiz.cn
ServerAlias www.mimiz.cn
Client accesses the domain name www.mimiz.cn
_ SERVER ["HTTP_HOST"] output www.mimiz.cn
_ SERVER ["SERVER_NAME"] output mimiz.cn
Therefore, in the actual program, we should try to use _ SERVER ["HTTP_HOST"], which is more safe and reliable.
In the case of port mapping and access on the intranet, it is better to use "$_ SERVER ['HTTP_X_FORWARDED_HOST']".
The above is all the contents of the article "what are the problems that may be ignored in PHP". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 277
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.