Php reference (&)-php Tutorial

Source: Internet
Author: User
Php reference (&)
##### Php reference allows two variables to point to the same content"
 "If an undefined variable is referenced and assigned with a reference parameter, the variable" function foo (& $ var) {} foo ($ ); var_dump ($ a); // output null $ B = array (); foo ($ B ['B']); var_dump (array_key_exists ('B ', $ B); // bool true $ c = new stdClass (); foo ($ c-> d); var_dump (property_exists ($ c, 'D ')); // bool true "if a declaration is given a reference to the global variable within a function, the reference is only visible within the function, you can avoid "$ var1 =" example variable "; $ var2 =" "; function global_references ($ use_globals) {global $ var1, $ var2; if (! $ Use_globals) {$ var2 = & $ var1;} else {$ GLOBALS ["var2"] = & $ var1 ;}} global_references (false ); echo "var2 is set to $ var2 "."
"; //" Var2 is set to "global_references (true); echo" var2 is set to $ var2 "."
"; //" Var2 is set to example variable "" when 'unset' is referenced, only the binding between the variable name and the variable content is broken, it does not mean that the content of the variable is destroyed" "Function Reference transfer" function test (& $ a) {$ a = $ a + 100;} $ B = 1; echo $ B; // output 1 test ($ B); // Here $ B is actually the memory address of the $ B variable content, by changing the value of $ a in the function, you can change the value of $ B by echo $ B; "function reference return" "The reference structure appears in the object-oriented model." class fucker {private $ data = 'hi'; public function & get () {return $ this-> data;} public function out () {echo $ this-> data ;}}$ q = new fucker (); $ d = & $ q-> get (); $ q-> out (); $ d = 'fuck'; $ q-> out (); $ d = 'u'; $ q-> out (); $ d = 'sir '; $ q-> out (); // hifuckusir"

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.