PHP Function Reference

Source: Internet
Author: User
function &referencefunc () {    static $foo = ';    return $foo;        } Pass a reference to the static variable $foo to $name$bar = &referencefunc (); $bar. = "Hello";//Call Echo Referencefunc () as a normal function;//delete reference unset ($bar) ;//As a normal function call $bar = Referencefunc (); $bar. = "World";//$foo does not change echo referencefunc ();

PHP's function reference is to return a reference to the function return value to the receive variable, the function declaration or call need to use the value operator &, but the call can also be used as a normal function directly (there is no function to reference the attribute, the receiving variable will point to the memory of the new address), There are also parameter references (value passing/reference passing), object reference

Breakout Class Package

Class Reference {    private $foo;    Public Function &referencefoo () {        return $this->foo;    }        Public Function Getfoo () {        echo $this->foo. "
"; }} $obj = new Reference ();//Bind the private variable on a common variable $bar $bar = & $obj->referencefoo ();//external operation private variable $bar. = "Access the private var in outside ";//output ' access the private var in outside ' $obj->getfoo ();

Of course function references are not used to do these things, and the main use of function references is to allow you to bind an additional alias to a property of the current object for easy operation

Note that the "&" operator is used when defining or calling, otherwise it is called as a normal function or method

  • 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.