代码如下:
<?php
$a = "hello world";
xdebug_debug_zval('a');
然后在PHP7下运行:
a: (refcount=2, is_ref=0)='hello world'
在PHP5.5下运行:
a: (refcount=1, is_ref=0)='hello world'
PHP 7的版本信息如下:
PHP 7.1.5 (cli) (built: May 9 2017 19:49:10) ( ZTS MSVC14 (Visual C++ 2015) x64 )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Xdebug v2.5.4, Copyright (c) 2002-2017, by Derick Rethans
PHP 5.5的版本信息如下:
PHP 5.5.1 (cli) (built: Jul 18 2013 10:56:37)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
为何PHP 7下变量的zval的refcount为何是2?
更新:今天再试了一下,在cmd命令下PHP 7.1还是显示2,然后通过浏览器访问的话,就是1,正常了,再去试了一下PHP7.0的,结果更诡异,显示的是0,如下:
λ C:\phpStudy\php\php-7.0.12-nts\php.exe -f test_zval.php
Hello_world: (refcount=0, is_ref=0)='hello world'
PHP版本如下:
λ C:\phpStudy\php\php-7.0.12-nts\php.exe -v
PHP 7.0.12 (cli) (built: Oct 13 2016 11:04:07) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans
感觉很有可能是我本地环境的问题,尤其是laragon集成环境的问题
手掌心