Home > Backend Development > PHP Tutorial > PHP reference operation and methods of local static variables of external operation functions_PHP tutorial

PHP reference operation and methods of local static variables of external operation functions_PHP tutorial

WBOY
Release: 2016-07-13 10:21:20
Original
1025 people have browsed it

PHP reference operations and methods of local static variables of external operation functions

Static variables inside functions or member methods are manipulated externally by reference

The following is a simple example to illustrate three issues related to citation:

1. Type conversion within the function after parameter reference is also an address operation

2. When passing parameters to other functions after quoting, you need to add the reference character again to maintain the address operation

3. The function return value reference must be added with the reference operator when the function is declared and called


This example uses the operation of object method, and the same applies to functions

<?php
class A {
	public function & test1(& $a) {
		static $i = 0;
		var_dump($i);
		$a = (array) $a;
		$a[&#39;domain&#39;] = &#39;http://blog.csdn.net/zhouzme&#39;;
		$this->test2($a);
		$i++;
		var_dump($a);
		var_dump($i);
		return $i;
	}

	protected function test2(& $a) {
		$a[&#39;name&#39;] = &#39;蜗牛&#39;;
	}
}

$obj = new A();
$a = &#39;&#39;;
$c = & $obj->test1($a);
$c++;
var_dump($a);
$obj->test1($a);
var_dump($a);
Copy after login


Output results







www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/859805.htmlTechArticlePHP reference operations and methods of local static variables of external operation functions are used inside external operation functions or member methods by reference Here is a simple example of static variables to illustrate...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template