1. As a weakly typed language, php does not need to explicitly indicate the type of variables, but php variables also have types, php Variables include the following 8 types of variables (three major categories)
a. Scalar type: boolean, integer, float (double), string
b. Composite type: array, object
c. Special types: resource, null
2.php uses c language to implement the principle of variables
a. Variable storage structure
typedef struct _zval_struct zval; ... struct _zval_struct { /* Variable information */ zvalue_value value; /*存储变量的值,是一个union类型*/ zend_uint refcount__gc;/*变量的引用计数,默认为1*/ zend_uchar type; /*变量的类型,为IS_NULL、IS_BOOL、IS_LONG、IS_DOUBLE、IS_STRING、IS_ARRAY、IS_OBJECT和IS_RESOURCE之一*/ zend_uchar is_ref__gc;/*表示是否为引用*/ };
b. The storage variable value zvalue_value is as follows
typedef union _zvalue_value { long lval; /* long value */ double dval; /* double value */ struct { char *val; int len; } str; HashTable *ht; /* hash table value */ zend_object_value obj; } zvalue_value;
Union is used here instead of struct to save memory space, because one variable can only represent one type at a time
Reference material: tipi open source project http://www.php-internals.com/book/?p=chapt03/03-01-00-variables-structure