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!