A brief summary of the differences between obfuscated functions such as ECHO (), print (), require (), and include ()

Source: Internet
Author: User

Address:Http://blog.licess.org/echo-print-require-include/

1. Differences between ECHO and print

The ECHO and print functions in PHP are basically the same (output), but there are still slight differences between the two. No return value after Echo output, but print has a return value. If the execution fails, flase is returned. Therefore, it can be used as a common function, such as executing the followingCodeThe value of the variable $ R is 1.

$ R = print "Hello world ";

This means that print is available in some complex expressions, but Echo is not. However, because the echo statement does not require any value to be returned, the running efficiency of the ECHO statement in the Code is slightly faster than that of the print statement.

2. Differences between include and require

The include () and require () functions are basically the same (include), but there are also some differences in usage. Include () is a conditional include function, while require () it is an unconditional include function. For example, in the following code, if the variable $ A is true, it will contain the file a. php:

If ($ ){
Include ("A. php ");
}

The require () is different from include (). No matter what the value of $ A is, the following code will include file a. php into the file:

If ($ ){
Require ("A. php ");
}

For error handling, use the include statement. If an include error occurs,ProgramThe include statement will be skipped. Although the error message will be displayed, the program will continue to execute! But requre will give you a fatal error.

Of course, we can also understand the literal meaning of 7 points: requre is a very tough request and requirement.

3. require_once () and include_once () Statements

Because of the long image, simple require_once () and include_once () Statements correspond to the require () and include () statements respectively. The require_once () and include_once () statements are mainly used to avoid repeated function or variable definition errors when you need to include multiple files.

4. Differences between null strings (") and null

PHP empty strings and null are both stored with 0 values, but their types are not the same. You can try echo GetType ("); and echo GetType (null ); you will find that the printed values are string and null, and of course there are also 0 which are easy to confuse. You can try echo GetType (0); print the type, the 0 type is INTEGER (integer). It can be seen that the string ("), null, and 0 are" equivalent "but not equal to the type.

5. Differences between isset and empty

Literally, we can understand that empty is used to determine whether a variable is "null", while isset is used to determine whether a variable has been set. However, when the value of a variable is 0, empty considers the variable to be null, that is, it is equivalent to no setting. For example, when we detect the $ id variable, when $ id = 0, empty and isset are used to check whether the variable $ ID has been configured. Both of them return different values: empty considers that there is no configuration, and isset can get the value of $ id. See the following example:
$ Id = 0;
Emptyempty ($ 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. Differences between = (wait) and = (constant)

Let's review the difference between the fourth Null String ("") and null. Let's look at an example:

"= NULL;
"= NULL;

After running, you will find that the first is true, and the second is false! It can be seen that = only compares whether the values are equal, while = compares not only the values, but also the types and stricter.

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.