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