Differences and usage of obfuscation functions in PHP

Source: Internet
Author: User
This article mainly introduces the differences and usage of PHP obfuscation functions, and summarizes examples such as echo and print, include and require ,! Isset, empty, and other functions are very practical skills. if you need them, you can refer to the examples in this article to analyze the differences and usage of PHP obfuscation functions. Share it with you for your reference. The specific analysis is as follows:

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. for example, after the following code is executed, the value of $ r is 1.

PHP code:

The code is as follows:

$ 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:

PHP code:

The code is as follows:

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:

PHP code:

The code is as follows:

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


For error handling, use the include statement. If an include error occurs, the program skips the include statement. Although the error message is displayed, the program continues 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). we can see that the string ("), NULL, and 0 are" equivalent ", but they are not of the same 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:

PHP code:

The code is as follows:

$ 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. Differences Between = (wait) and = (constant)

Let's review the difference between the fourth NULL string ("") and NULL. let's look at an example:

PHP code:

The code is as follows:

"= 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.

I hope this article will help you with php programming.

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.