PHP variable reference counter and write-time replication

Source: Internet
Author: User
Tags php language

It is well known that PHP does not support pointers, but what if you want two variables to point to the same memory block at the same time? To solve this problem, a reference counter is used in the PHP kernel.
The previous post describes how PHP variables are stored in the kernel, and the following two member variables in the ZVAL structure are used to reference counters:

is_ref  BOOL值,标识变量是否是引用集合。refcount  计算指向引用集合的变量个数。

Look at the following PHP code


  
   

An entity of a zval structure is called a zval container. Creating a variable in the PHP language layer will create a zval container in the PHP kernel accordingly. Because the code above creates a variable $ A, a zval container is created in the PHP kernel, and because the variable is not a reference, the is_ref of the Zval container equals false, and refcount equals 1.
And look at the code below.


  
   

The above code creates two variables a and

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the PHP variable reference counter and write-time replication, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.