Home > Backend Development > PHP Tutorial > php static变量的refcount为何是2,is_ref为何是1?

php static变量的refcount为何是2,is_ref为何是1?

WBOY
Release: 2016-06-06 20:33:23
Original
1427 people have browsed it

<code><?php $a = 1;
    xdebug_debug_zval("a");
    static $b = 1;
    xdebug_debug_zval("b");
?>
</code>
Copy after login
Copy after login

为何执行后输出是
a: (refcount=1, is_ref=0)=1
b: (refcount=2, is_ref=1)=1
static变量和普通变量为何会有这样的区别?

回复内容:

<code><?php $a = 1;
    xdebug_debug_zval("a");
    static $b = 1;
    xdebug_debug_zval("b");
?>
</code>
Copy after login
Copy after login

为何执行后输出是
a: (refcount=1, is_ref=0)=1
b: (refcount=2, is_ref=1)=1
static变量和普通变量为何会有这样的区别?

refcount是计数次数,如果为0 就是被销毁
如果用Unset 这个数会减1
is_ref是表示引用
猜想:这表变量里的内容是另一个内存地址(也就是真实的内容),然后unset只会删除这个变量,并不会删除这个内存地址里面的东西
http://php.net/manual/zh/features.gc.refcounting-basics.php

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template