Highlights of PHP

Source: Internet
Author: User
The best use of PHP reference is: bardo. iteye. comadminblogs848136? I have already explained in detail what is reference. Here we will give you a brief introduction to the usage of references. 1. Reference passing parameters, which has two functions. one is to make the external variables and the variables in the function change synchronously. Second, multiple parameters can be returned without return. 2. for large data structures, reduce replication to reduce memory consumption. This is a common purpose. Introducing PHP reference

In: http://bardo.iteye.com/admin/blogs/848136? I have already explained in detail what is reference. Here we will give you a brief introduction to the usage of references.

1. Reference passing parameters, which has two functions. one is to make the external variables and the variables in the function change synchronously. Second, multiple parameters can be returned without return.

2. for large data structures, reduce replication to reduce memory consumption.

This is a common purpose. In fact, there are still some amazing uses that are unknown. At present, we have just found one:

?

If a file contains code, if we use the following code in SHELL state:

$ Host = $ _ SERVER ['http _ host'];

The notice information appears in the log. Of course, if you close it, it does not mean it is not generated. However, in order to make the web page and SHELL usable, we still need to do this:

1:

Disable error_reporting (245.

Second, directly prevent it from appearing:

$ Host = @ $ _ SERVER ['http _ host'];

Third, use the ternary operator.

$ Host = (isset ($ _ SERVER ['http _ host'])? $ _ SERVER ['http _ host']: '';

?

However, this is a common method.

In fact, there is another way to prevent it from having notice information:

?

$ Host = & $ _ SERVER ['http _ host'];

?

In this way, we guarantee that the isset or @

?

Isset is used only when variables are actually used. This not only reduces the number of characters in the code, but also accelerates the running efficiency.

?

Now, try the following code to see if it is running like this.

?

Error_reporting (E_ALL); $ ar = array (); $ B = & $ ar ['test']; // you can try the previous method in this line $ c = '23 '. $ B. '31'; echo ($ c );

?

? Of course, when using the reference, the biggest note is that you must ensure that it cannot be changed during use. Otherwise, the original variable must be synchronized and changed in advance.

?

Therefore, if you cannot predict, use @

?

Input method on the first floor

Really amazing!

Related Article

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.