Reference counters and write-time replication of php variables

Source: Internet
Author: User
: This article mainly introduces the reference counters and write-time replication of php variables. For more information about PHP tutorials, see. As we all know, PHP does not support pointers, but what if we want two variables to point to the same memory block at the same time? To solve this problem, the reference counter is used in the PHP kernel.
The previous blog introduces the storage of PHP variables in the kernel. in the zval structure, the following two member variables are used to reference counters:

Is_ref BOOL value to identify whether the variable is a reference set. Refcount calculates the number of variables pointing to the referenced set.

See the following php code.



  

The object of a zval structure is called the zval container. When a variable is created at the php language layer, a zval container is created in the php kernel accordingly. Because the above code creates a variable $ a, a zval container will be created in the php kernel; and because this variable is not a reference, the is_ref of the zval container is equal to FALSE, and refcount is equal to 1.
Let's look at the following code.



  

The above code creates two variables A and

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above introduces the reference counters and write-time replication of php variables, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

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.