1.zval是php变量底层定义的结构,一共16字节
typedef struct _zval_struct zval;
struct _zval_struct {
zend_value value;
union u1;
union u2;
};
zval 的详细结构如下:
zend_value 是一个联合体 它的大小是8个字节
u1 联合体 4个字节
u2 联合体 4个字节
共16字节
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; //4个字节
//ZEND_ENDIAN_LOHI_4 定义 define ZEND_ENDIAN_LOHI_4(a, b, c, d) d; c; b; a;
//typedef unsigned char zend_uchar;
uint32_t type_info; //4个字节
} u1;
union {
uint32_t next; /* hash collision chain 用来解决哈希冲突问题,记录冲突的下一个元素位置*/
uint32_t cache_slot; /* literal cache slot 运行时缓存。在执行函数时会优先去缓存中查找,若缓存中没有,会在全局的function表中查找*/
uint32_t lineno; /* line number (for ast nodes) 文件执行的行号,应用在AST节点上 */
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 */