Home >Backend Development >PHP Tutorial >基础题:对象引用有关问题

基础题:对象引用有关问题

WBOY
WBOYOriginal
2016-06-13 11:42:27819browse

基础题:对象引用问题?

<?php<br />$global_obj=null;<br /><br />class Demo{<br />	var $my_val;<br />	public function __construct(){<br />		global $global_obj;<br />		$global_obj=&$this;<br />	}<br />}<br /><br />$p=new Demo();<br /><br />$p->my_val=5;<br /><br />global $global_obj;<br /><br />$global_obj->my_val=10;<br /><br />echo $p->my_val;  //输出5<br /><br />var_dump($p===$global_obj);  //返回false<br />?>


请问为什么结果是5 而不是10;
我的理解是:PHP5中,除非你用clone关键字明确要克隆一个对象,否则将永远不会无意识地复制对象。
这样理解对吗?

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