PHP弱数据类型的内部实现

PHP那个该死的若类型是怎么实现的

打开php代码中Zend.h和Zend_types.h可以看到有如下定义:


typedef union _zvalue_value {
    long lval;          /* 长整形 */
    double dval;        /* 双精度 */
    struct {
        char *val;
        int len;
    } str;		/*字符串*/
    HashTable *ht;      /*hash表 */
    zend_object obj;    /*PHP对象存储结构*/
} zvalue_value;

struct _zval_struct {
    zvalue_value value; /*值*/
    zend_uchar type;    /*当前类型*/
    zend_uchar is_ref;  /*。。。。。。。。。。。。。。看起来是是否被引用了*/
    zend_ushort refcount;  /*引用计数器*/
};

typedef struct _zval_struct zval;
typedef zval pval;

/*这玩意就是一个句柄表么*/
typedef unsigned int zend_object_handle;
typedef struct _zend_object_handlers zend_object_handlers;


typedef struct _zend_object_value {
    zend_object_handle handle;
    zend_object_handlers *handlers;
} zend_object_value;


/*对象结构体*/
struct _zend_object_handlers {
	/* general object functions */
	zend_object_add_ref_t					add_ref;
	zend_object_del_ref_t					del_ref;
	zend_object_clone_obj_t					clone_obj;
	/* individual object functions */
	zend_object_read_property_t				read_property;
	zend_object_write_property_t			write_property;
	zend_object_read_dimension_t			read_dimension;
	zend_object_write_dimension_t			write_dimension;
	zend_object_get_property_ptr_ptr_t		get_property_ptr_ptr;
	zend_object_get_t						get;
	zend_object_set_t						set;
	zend_object_has_property_t				has_property;
	zend_object_unset_property_t			unset_property;
	zend_object_has_dimension_t				has_dimension;
	zend_object_unset_dimension_t			unset_dimension;
	zend_object_get_properties_t			get_properties;
	zend_object_get_method_t				get_method;
	zend_object_call_method_t				call_method;
	zend_object_get_constructor_t			get_constructor;
	zend_object_get_class_entry_t			get_class_entry;
	zend_object_get_class_name_t			get_class_name;
	zend_object_compare_t					compare_objects;
	zend_object_cast_t						cast_object;
	zend_object_count_elements_t			count_elements;
	zend_object_get_debug_info_t			get_debug_info;
	zend_object_get_closure_t				get_closure;

}

这个结构体里面实现了:长整型,双精度浮点,字符串,hash表,还有对象(zend_object_value)。就是zval和pval两个结构。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值