PHP is often easy to keep in mind about confusing knowledge

Source: Internet
Author: User
Tags empty error handling http request include php class variable access port number

the difference between 1.echo and print

The functions of ECHO and print are essentially the same in PHP (output), but there is a slight difference between the two. echo output does not return a value, but print has a return value that returns Flase when its execution fails. So it can be used as a normal function, such as executing the following code, the value of the variable "will be 1."

$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 is more efficient to run than the print statement.

the difference between 2.include and require

The features of include () and require () are basically the same (included), but there are some differences in usage, include () is a conditional include function, and require () is an unconditional include function. For example, in the following code, if the variable $a is true, the file a.php will be included:

if ($a) {

Include ("a.php");

}

and require () differs from include (), regardless of $a value, the following code will include the file a.php in the file:

if ($a) {

Require ("a.php");

}

In the case of error handling, using the Include statement, if a include error occurs, the program skips the include statement, although an error message is displayed but the program continues to execute! But Requre will give you a fatal error.

Of course, in literal terms we can also understand seven points: Requre is a very tough request, the meaning of the request.

3.require_once () and include_once () statements

The digression, because of the long image, the simple require_once () and the include_once () statements correspond to the require () and include () statements respectively. The require_once () and include_once () statements are primarily used when you want to include multiple files, and you can effectively avoid the error of repeating a function or variable definition by including the same piece of code.

4. The difference between an empty string (') and null

The PHP hollow string and null are all stored in value 0, but their type is not the same, you can try Echo GetType ("); and Echo gettype (NULL); you will find that they are printed with string and null respectively, Of course, 0 is also easy to confuse, you can try the Echo GetType (0), print the type, you will find that 0 of the type is Integer (integer), the Visible string ("), null and 0 are" equivalent "but unequal type.

the difference between 5.isset and empty

On the literal sense, we can see that the empty is to judge whether a variable is "empty", while isset is to determine whether a variable has been set. But here's one thing to be absolutely aware of: When a variable value is 0,empty that the variable equals null, that's equivalent to no setting. For example, when we detect $id variables, when $id=0, with empty and isset to detect whether the variable $id has been configured, both will return a different value: empty think there is no configuration, isset can get $id value, look at the following example:

$id = 0;

Empty ($id) print "I am Empty":p rint "I am $id"; Result: I was empty.

!isset ($id) print "I am Empty":p rint "I am $id"; /Result: I am 0

the difference between 6.== (ET) and = = = (identity)

Review the difference between the fourth empty string ("") above and null, and then look at an example:

' = = NULL;

' = = NULL;

After the run you will find that the first one is true, and the second is false! visible = = Only the comparison value is equal, and = = = Not only compares the value, but also compares the type, more strict.

7.self:: The difference with this->

When accessing a member variable or method in a PHP class, if the referenced variable or method is declared as a const (defined constant) or static (declaring static), then the operator must be used:: Conversely, if the referenced variable or method is not declared as const or static, Then you must use the operator->.

In addition, if you are accessing a const or static variable or method from within a class, you must use self-quoted self, whereas if the internal access from the class is not a const or static variable or method, you must use the $this of the self reference.

the difference between 8.strstr () and Strpos ()

STRISTR () case-insensitive strstr () case sensitive

function to find where the string first appears in another string.

If successful, the remainder of the string is returned (from the match point). If the string is not found, it returns false.

Stripos () case-insensitive strpos () case sensitive

function to return the first occurrence of a string in another string.

If the string is not found, it returns false.

The test proves that if only a simple lookup is available, the Strpos () is more efficient than strstr ()

9.PHP http_host and server_name

Same point:

The same information is output when the following three conditions are met.

1. Server is 80 port

2. apache servername settings are correct

3. http/1.1 Protocol Specification

Different points:

1. Usually the case:

_server["Http_host"], under the HTTP/1.1 protocol specification, outputs information based on the client's HTTP request.

_server["SERVER_NAME"] directly outputs the servername value in the Apache configuration file httpd.conf by default.

2. When the server is not 80 ports:

_server["Http_host"] outputs the port number, for example: mimiz.cn:8080

_server["SERVER_NAME"] directly outputs servername values

So in this case, it can be understood as: Http_host = Server_name:server_port

3. When the ServerName in the profile 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 Access domain name www.mimiz.cn

_server["Http_host"] Output www.mimiz.cn

_server["SERVER_NAME"] Output mimiz.cn

Therefore, in the actual procedure, should try to use _server["http_host"], compare insurance and reliable.

If in the case of port mapping, and in the intranet access, with "$_server[' Http_x_forwarded_host '" is better.

Original address: http://www.cnblogs.com/qibuweb/archive/2012/02/21/2362009.html



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.