php debug 打印变量_PHP: debug_zval_dump - Manual

注意:

Understanding the refcount

The refcount value shown by this function may be

surprising without a detailed understanding of the engine's implementation.

The Zend Engine uses reference counting for two different purposes:

Optimizing memory usage using a technique called "copy on write",

where multiple variables holding the same value point to the same copy

in memory. When any of the variables is modified, it is pointed to a new

copy in memory, and the reference count on the original is decreased by 1.

Tracking variables which have been assigned or passed by reference (see

References Explained). This

refcount is stored on a separate reference zval, pointing to the zval

for the current value. This additional zval is not currently shown by

debug_zval_dump().

Because debug_zval_dump() takes its input as normal

parameters, passed by value, the copy on write technique will be used

to pass them: rather than copying the data, the refcount will be increased

by one for the lifetime of the function call. If the function modified the

parameter after receiving it, then a copy would be made; since it does not,

it will show a refcount one higher than in the calling scope.

The parameter passing also prevents debug_zval_dump()

showing variables which have been assigned by reference. To illustrate,

consider a slightly modified version of the above example:

$var1='Hello';$var1.=' World';// Point three variables as references to the same value$var2=&$var1;$var3=&$var1;debug_zval_dump($var1);?>

以上例程会输出:

string(11) "Hello World" refcount(2)

Although $var1, $var2, and

$var3 are linked as references, only the

value is passed to debug_zval_dump().

That value is used once by the set of references, and once inside the

debug_zval_dump(), so shows a refcount of 2.

Further complications arise because of optimisations made in the engine for

different data types. Some types such as integers do not use "copy on write",

so do not show a refcount at all. In other cases, the refcount shows extra

copies used internally, such as when a literal string or array is stored as

part of a code instruction.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值