php 变量的结构和实现
php版本 7.2.3
文件地址:Zend/zend_types.h
typedef struct _zval_struct zval;
变量的存储结构
struct _zval_struct { zend_value value; /* value */ union { struct { ZEND_ENDIAN_LOHI_4( zend_uchar type, /* active type */ zend_uchar type_flags, zend_uchar const_flags, zend_uchar reserved) /* call info for EX(This) */ } v; uint32_t type_info; } u1; union { uint32_t next; /* hash collision chain */ uint32_t cache_slot; /* literal cache slot */ uint32_t lineno; /* line number (for ast nodes) */ uint32_t num_args; /* arguments number for EX(This) */ uint32_t fe_pos; /* foreach position */ uint32_t fe_iter_idx; /* foreach iterator index */ uint32_t access_flags; /* class constant access flags */ uint32_t property_guard; /* single property guard */ uint32_t extra; /* not further specified */ } u2; };
value:存放变量值
u1:变量的属性
u2:变量被使用时使用
变量值的实际存储结构,一个联合体(节省空间)
1 typedef union _zend_value { 2 zend_long lval; /* long value */ 3 double dval; /* double value */ 4 zend_refcounted *counted; 5 zend_string *str; 6 zend_array *arr; 7 zend_object *obj; 8 zend_resource *res; 9 zend_reference *ref; 10 zend_ast_ref *ast; 11 zval *zv; 12 void *ptr; 13 zend_class_entry *ce; 14 zend_function *func; 15 struct { 16 uint32_t w1; 17 uint32_t w2; 18 } ww; 19 } zend_value;
for remember