The method of PHP reference operation and local static variables of external operation function

Source: Internet
Author: User

Static variables inside an external action function or member method by reference

Here's a simple example that illustrates three questions about references:

1. Parameter reference after the function of the type conversion is also the address operation

2. The reference character needs to be added again when the parameter reference is passed to another function to keep the address operation

3. Function return value reference must add a reference operator when the function is declared and when called


This example uses the action of an object method, and also applies to a function

 
 Test2 ($a);
		$i + +;
		Var_dump ($a);
		Var_dump ($i);
		return $i;
	}

	protected function Test2 (& $a) {
		$a [' name '] = ' snail ';
	}
}

$obj = new A ();
$a = ';
$c = & $obj->test1 ($a);
$c + +;
Var_dump ($a);
$obj->test1 ($a);
Var_dump ($a);


Results of output









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.