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.