Why does the function of PHP add 2 to the formal parameter refcount?

Source: Internet
Author: User

  
   

Reply content:


  
    

Well, the Lazyboy asked me to find out the answer: the refcount of the parameter passing value

Example content from 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 have a single reference (as did $var 1 before it is used as an argument to debugzvalDump ()), PHP ' s Engine optimizes the manner in which it's passed to a function. Internally, PHP treats $var 1 like a reference (in the. The refcount is increased for the scope of this function), with the Caveat that if the passed reference happens to being written to, a copy was 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 is made. Until then, the parameter remains a reference, causing the refcount to being incremented to 2 for the scope of the function C All.

The Xdebugdebugzval is transmitted in a quoted manner.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.