What is exactly happening when instantiating with 'new'?

爱⌒轻易说出口 提交于 2019-12-03 01:50:16

Adding another instantiation $obj2 = new a; increases the refcount to 3, not 4, so it's something which happens as a result of calling xdebug_debug_zval. The purpose of the xdebug function is to avoid the confusion from the passing the variable into the function and (possibly) creating an extra reference.

Unfortunately, this does not apply to the member variables; another reference is created to those zvals in order to export them. Therefore, all the caveats and confusing circumstances listed in the note on the debug_zval_dump documentation still apply for the member variables.

I think the section "Note: Beware the refcount" on the following page explains this: http://php.net/manual/en/function.debug-zval-dump.php

It shows that the ref count increases if zend optimizes how it's passed, but then the "caveat" being when copy-on-write is invoked, returning the refcount back down to 1.

Hope that helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!