: This article mainly introduces reference counting of variables learned in php. For more information about PHP tutorials, see. What is the reference count of php variables? First, let's take a look at the underlying structure of php variables:
Typedef struct _ zval_struct zval; struct _ zval_struct {zvalue_value value; // store value into refcount _ gc; // reference count zend_uchar type; // Judge type zend_uchar is_ref _ gc; // whether it is referenced };
When we declare a variable in the php program, the zend Engine will instantiate a zval struct, which has four member variables. Here, type is used to determine the type of the variable. value is used to store actual data. In fact, value is also a struct, which is not detailed here. Today we will focus on the usefulness of the refcount_gc and is_ref_gc fields. Suppose there is such a piece of code:
$ A = 123; $ B = $;
Because of a simple int type variable, php needs to instantiate a struct. in this case A and
Copyright Disclaimer: This article is an original article by the blogger. For more information, see the source.
The above describes the reference counting of php variables, including the reference counting. I hope to help anyone who is interested in PHP tutorials.