1.php中的变量不用申明类型,类型和值存储在同一结构体中
类型用char标识(4),值用联合体(8),还有一块用来存储其他比如next(解决哈希冲突),foreach的指针等(4)
// 值用联合体(内存占用8)
typedef union _zend_value {
zend_long lval; /* long value */
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; /* zval类型 */
void *ptr; /* 指针类型 */
zend_class_entry *ce;
zend_function *func;
struct {
uint32_t w1;
uint32_t w2;
} ww;
} zend_value;
struct _zval_struct {
zend_value value; /* value 值用联合体 */
// 长度为4
union {
struct {
ZEND_ENDIAN_LOHI_4(
zend_uchar type, /* active type 类型用char标识(内存占用4)*/
zend_uchar type_flags, /* 对应变量类型特有的标记 */
zend_uchar const_flags, /* 常量类型标记 */
zend_uchar reserved) /* call info for EX(This) 保留字段 */
} v;
uint32_t type_info;
} u1;
// 长度为4
union {
uint32_t next; /* hash collision chain 用来解决哈希冲突*/
uint32_t cache_slot; /* literal cache slot 运行时缓存*/
uint32_t lineno; /* line number (for ast nodes) 对于zend_ast_zval存行号*/
uint32_t num_args; /* arguments number for EX(This) EX(this)参数个数*/
uint32_t fe_pos; /* foreach position foreach位置*/
uint32_t fe_iter_idx; /* foreach iterator index foreach游标的标记*/
uint32_t access_flags; /* class constant access flags 类常量访问标识*/
uint32_t property_guard; /* single property guard 单一属性保护*/
} u2;
};
2.类型一共20种 基本11+常量\抽象语法树(2)+7个内部变量
/* regular data types 基本类型11*/
#define IS_UNDEF 0
#define IS_NULL 1
#define IS_FALSE 2
#define IS_TRUE 3
#define IS_LONG 4
#define IS_DOUBLE 5
#define IS_STRING 6
#define IS_ARRAY 7
#define IS_OBJECT 8
#define IS_RESOURCE 9
#define IS_REFERENCE 10
/* constant expressions 常量\抽象语法树(2 */
#define IS_CONSTANT 11
#define IS_CONSTANT_AST 12
/* fake types 伪类型*/
#define _IS_BOOL 13
#define IS_CALLABLE 14
#define IS_ITERABLE 19
#define IS_VOID 18
/* internal types 4个内部类型*/
#define IS_INDIRECT 15
#define IS_PTR 17
#define _IS_ERROR 20
3.string类型结构体 (32)
垃圾回收东东gc(8+8,存复杂类型的type)、
长度(size_t 8)、
值数组(只存1,val[1] 柔性数组,只能放在结构体底部,1内存对齐8)
struct _zend_string {
zend_refcounted_h gc; /* 垃圾回收 */
zend_ulong h; /* hash value */
size_t len; // 存长度,内存占用8
char val[1]; // 柔性数组
};
4.hash
找到hashkey,找值。时间复杂度o1
解决hash冲突,链表(on),其他数据接口替换链表,重新分配大小
5.gdb调试过程演示
01.代码实例
02.打断点
03.整型
04.浮点型
05.字符串
06.字符串详情
6.视频地址
http://replay.xesv5.com/ll/2480/af2fbe1abebfe343f08b38161d49d8b4.flv.mp4
7.笔记地址 d4 变量存储