Zend/zend_types.h
Zend/zend_variables.h
Zend/zend_variables.c
struct
# 变量
struct _zval_struct {
// 变量值
zend_value value; /* value */
union {
struct {
ZEND_ENDIAN_LOHI_4(
// 变量类型
// true,false,null 直接在type中区分 不存值
zend_uchar type, /* active type */
// GC时用到
zend_uchar type_flags,
zend_uchar const_flags,
zend_uchar reserved) /* call info for EX(This) */
} v;
// 上面4个值的组合值
uint32_t type_info;
} u1;
// 一些辅助值
union {
uint32_t var_flags;
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 */
} u2;
};
# 变量值
typedef union _zend_value {
// php整数 直接存储值
zend_long lval; /* long value */
// php中的浮点数 直接存储值
double dval; /* double value */
zend_refcounted *counted;
// 字符串
zend_string *str;
// 数组
zend_array *arr;
// 对象
zend_object *obj;
// 资源型
zend_resource *res;
// 引用类型
zend_reference *ref;
zend_ast_ref *ast;
zval *zv;
void *ptr;
zend_class_entry *ce;
zend_function *func;
struct {
uint32_t w1;
uint32_t w2;
} ww;
} zend_value;
字符串 zend_string
# 字符串
struct _zend_string {
zend_refcounted_h gc;
zend_ulong h; /* hash value */
// 二进制安全
size_t len;
char val[1];
};
zend_object
struct _zend_object {
zend_refcounted_h gc;
uint32_t handle;
zend_class_entry *ce;
const zend_object_handlers *handlers;
HashTable *properties;
zval properties_table[1];
};
zend_resource
struct _zend_resource {
zend_refcounted_h gc;
int handle;
int type;
void *ptr;
};
zend_reference
struct _zend_reference {
zend_refcounted_h gc;
zval val;
};
创建
引用计数 + 写时复制