php7 引用成為一種型別

2022-03-10 22:13:47 字數 671 閱讀 2392

<?php

$a="

abc"; is_ref=0 ref_count=1

$b=$a; is_ref=0 ref_count= 2

$c=&$a; is_ref=1 ref_count 2

即a c 共用乙個zval, b單獨用乙個zval 當然 ref_count為1

$c=2

;$a=range(10000

);$b=&$a;

count($a1);

相當於$a1=$a; 那麼在count內部需要複製$a,因為在php7之前 引用變數 和非引用變數不能使用同乙個zval,必須分享

php7不分離,只有當$a1改變時,才分離

$a=range(10000)  refcount 1

$b=&$a   ref (refcount=2)  val(refcount=1)

$a1=$a   ref(refcount=2) val(refcount=2)

unset($a)  ref(refcount=1) val(refcount=2)

unset($b)  ref (refcount =0 delete) val(refcount = 1)

unset($a1)  val(refcount=0 **記憶體  zend_string)

PHP7引用型別

php5在引入引用計數後,使用了refcount gc來記錄次數,同時使用is ref gc來記錄是否是引用型別。例如 a hello a zval1 type is string,refcount gc 1,is ref gc 0 這個時候 a指向乙個結構體,主要看refcount gc 1,這就...

PHP7 引入的「 」 和「 」的區別

實踐出真知 輸入測試 array a 1,b 2,c a array c 0 b array c 0 c array d 0 d array d 0 e array c 1 0 f isset array c 1 0 g array d 1 0 h isset array d e 1 0 i emp...

PHP7 引入的「 」 和「 」的區別

實踐出真知 輸入測試 array a 1,b 2,c a array c 0 b array c 0 c array d 0 d array d 0 e array c 1 0 f isset array c 1 0 g array d 1 0 h isset array d e 1 0 i emp...