Home >Backend Development >PHP Problem >What does PHP ZVAL mean?
PHP ZVAL is one of the most important data structures in PHP. It contains information about variable values and types in PHP. It is a struct structure. The basic structure is [struct _zval_struct (zvalue_value value zend_uchar type)] .
##PHP ZVAL means:
The basic structure of ZVAL
Zval is one of the most important data structures in PHP (another important data structure ishash table), which contains information about variable values and types in PHP.
struct _zval_struct { zvalue_value value; /* 存储变量的值*/ zend_uint refcount__gc; /* 表示引用计数 */ zend_uchar type; /* 变量具体的类型 */ zend_uchar is_ref__gc; /* 表示是否为引用 */ }; typedef struct _zval_struct zval;Among them:
1, zval_value value
zvalue_value:
typedef union _zvalue_value { long lval; /* long value */ double dval; /* double value */ struct { /* string */ char *val; int len; } str; HashTable *ht; /* hash table value,used for array */ zend_object_value obj; /* object */ } zvalue_value;
2, zend_uint refcount__gc
3. zend_uchar type
##This field is used to indicate the actual type of the variable. When we started learning PHP, we already knew that variables in PHP include four scalar classes (bool, int, float, string), two composite types (array, object) and two special types (resource and NULL) .
Inside zend, these types correspond to the following macros (code location
phpsrc/Zend/zend.h): <pre class="brush:php;toolbar:false">#define IS_NULL 0
#define IS_LONG 1
#define IS_DOUBLE 2
#define IS_BOOL 3
#define IS_ARRAY 4
#define IS_OBJECT 5
#define IS_STRING 6
#define IS_RESOURCE 7
#define IS_CONSTANT 8
#define IS_CONSTANT_ARRAY 9
#define IS_CALLABLE 10</pre>
is_ref__gc
This field is used to mark whether the variable is a reference variable. For ordinary variables, the value is 0, and for reference variables, the value is 1. This variable will affect the sharing, separation, etc. of zval. We will discuss this later.
As the name suggests,
ref_count__gc and is_ref__gc
are two very important fields required by PHP’s GC mechanism. The values of these two fields can be passed Check with debugging tools such as xdebug.
PHP programming from entry to proficiency
The above is the detailed content of What does PHP ZVAL mean?. For more information, please follow other related articles on the PHP Chinese website!