标量的区别
- php7不在计数 refcount都是为0
<?php
$a = 1;
xdebug_debug_zval('a');
echo PHP_EOL;
$b = $a;
xdebug_debug_zval('a');
结果:
a: (refcount=0, is_ref=0)=1
a: (refcount=0, is_ref=0)=1
复合类型数据区别
- 复合类型数组和对象在zval容器例子
php7 数组的引用计数都是从2开始, php5从1开始
$a = array( 'meaning' => 'life', 'number' => 42 );
xdebug_debug_zval( 'a' );
结果:
a: (refcount=2, is_ref=0)=array ('meaning' => (refcount=1, is_ref=0)='life', 'nu
mber' => (refcount=0, is_ref=0)=42)
php7 对象属性的标量引入计数都是0不参与计数
class Test{
public $a = "aa";
public $b = 2;
function handle(){
echo 'hehe';
}
}
$test = new Test();
$b = $test;
xdebug_debug_zval('test');
结果:
test: (refcount=2, is_ref=0)=class Test { public $a = (refcount=0, is_ref=0)='aa
'; public $b = (refcount=0, is_ref=0)=2 }