您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php的函数的形参refcount为何要加2?

2026/2/5 19:36:26发布13次查看

回复内容:
好吧,德问的lazyboy帮我查到答案了: 形参传值时的refcount
例子内容来自http://julien-pauli.developpez.com/tutoriels/php/internals/variables/?page=page_6
a refcount of 2, here, is extremely non-obvious. especially considering the above examples. so what's happening?
when a variable has a single reference (as did $var1 before it was used as an argument to debugzvaldump()), php's engine optimizes the manner in which it is passed to a function. internally, php treats $var1 like a reference (in that the refcount is increased for the scope of this function), with the caveat that if the passed reference happens to be written to, a copy is made, but only at the moment of writing. this is known as copy on write.
so, if debugzvaldump() happened to write to its sole parameter (and it doesn't), then a copy would be made. until then, the parameter remains a reference, causing the refcount to be incremented to 2 for the scope of the function call.
xdebugdebugzval 是采用引用的方式传值的。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product