1锛屼粈涔堟槸寮曠敤鍙橀噺锛熷湪php褰撲腑锛岀敤浠涔堢鍙峰畾涔夊紩鐢ㄥ彉閲
鍦≒HP涓紩鐢ㄦ剰鍛崇潃涓嶅悓鐨勫悕瀛楄闂悓涓涓彉閲忓唴瀹癸紱&
php寮曠敤鍙橀噺鐨勫伐浣滃師鐞
璇磋捣鏉hp寮曠敤鍙橀噺锛屼笉寰椾笉璇磒hp鐨勫彉閲忋
姣忎釜php鍙橀噺瀛樺湪涓涓彨”zval”鐨勫彉閲忓鍣ㄤ腑锛屼竴涓獄val鍙橀噺瀹瑰櫒锛岄櫎浜嗗寘鍚彉閲忕殑绫诲瀷鍜屽硷紝杩樺寘鎷袱涓瓧鑺傜殑棰濆淇℃伅銆傜涓涓槸”is_ref”锛屾槸涓猙ool鍊硷紝鐢ㄦ潵鏍囪瘑杩欎釜鍙橀噺鏄惁鏄睘浜庡紩鐢ㄩ泦鍚堬紱鍙﹀涓涓槸”refcount”,鐢ㄤ互琛ㄧず鎸囧悜杩欎釜zval鍙橀噺瀹瑰櫒鐨勫彉閲(涔熺О绗﹀彿鍗硈ymbol)涓暟
鎯宠鏌ョ湅杩欎袱涓肩殑璇濓紝鍙互瀹夎涓涓媝hp鐨刋DEBUG锛岀劧鍚庝娇鐢▁debug_debug_zval鍑芥暟锛屼紶鍏ュ彉閲忕殑鍙傛暟鍚嶅瓧灏卞彲浠ヤ簡锛屽
<?php
$a = array( 'one' );
$b =& $a;
xdebug_debug_zval( 'a' );
?>
鎵撳嵃鍑烘潵鐨勫兼槸
a:
(refcount=2, is_ref=1)
array (size=1)
0 => (refcount=2, is_ref=0)string ‘one’ (length=3)
unset($b)
class Person
{
public $name ="zhangsan";
}
$p1 = new Person;
xdebug_debug_zval('p1');
$p2 = $p1;
xdebug_debug_zval('p1');
$p2->name = 'lisi';
xdebug_debug_zval('p1');
鎵撳嵃鍑烘潵鐨勫兼槸
p1:
(refcount=1, is_ref=0)
object(Person)[1]
public ‘name’ => (refcount=2, is_ref=0)string ‘zhangsan’ (length=8)
p1:
(refcount=2, is_ref=0)
object(Person)[1]
public ‘name’ => (refcount=2, is_ref=0)string ‘zhangsan’ (length=8)
p1:
(refcount=2, is_ref=0)
object(Person)[1]
public ‘name’ => (refcount=0, is_ref=0)string ‘lisi’ (length=4)
鍐欏嚭濡備笅绋嬪簭鐨勮緭鍑虹粨鏋
<?php
$data = ['a','b','c'];
foreach ($data as $key=>$val){
$val = &$data[$key];
}
绋嬪簭姣忎竴娆″惊鐜悗锛$data鐨勫兼槸浠涔
绋嬪簭鎵ц瀹屾垚涔嬪悗锛屽彉閲$data鐨勫兼槸浠涔堛
绗竴娆″惊鐜,$key=0,$val=a,鐒跺悗$val=&$data[0],鎵浠$data杩樻槸[‘a’,’b’,’c’]
绗簩娆″惊鐜瘮杈冮噸瑕,$key=1,$val=b,杩欎釜鏃跺欏洜涓烘槸浼犻掑紩鐢紝鎵浠ュ氨鏀瑰彉浜$data[0]鐨勫硷紝鎵浠$data灏辨槸[‘b’,’b’,’c’]
鎵浠ョ涓夋鍚岀悊灏辨槸,鎵浠$data灏辨槸[‘b’,’c’,’c’]浜嗐
鍙戣〃鍥炲