Home  >  Article  >  Backend Development  >  php学习笔记之指向对象的变量

php学习笔记之指向对象的变量

WBOY
WBOYOriginal
2016-06-23 13:40:061154browse

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>无标题文档</title><?php class A	{		public $name = "Jhon";	}		class Person	{		private $a;				function SetA($_a = "Tom")		{			$this->a = $_a;		}				function UpdateA($_a = "Tom")		{			$this->a->name = $_a;		}				function GetA()		{			return $this->a;		}	}		$p = new Person();	$a1 = new A();		echo($a1->name . "<br>");		$p->SetA($a1);//调用SetA方法,将对象传入	echo($p->GetA()->name . "<br>");//$p->GetA()返回的是A的对象,->name就是它的属性name	//注意:在php3中,指向对象的变量是引用变量。在这个变量里面存储的是指向对象的内存地址。引用变量传值时,传递的是这个对象的指向,而非复制这个对象。	$p->UpdateA();	echo($p->GetA()->name . "<br>");		$p->UpdateA("Mike");	echo($p->GetA()->name . "<br>");		echo($a1->name . "<br>");?>

Statement:
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