PHP variable principle, PHP variable
1.php, as a weakly typed language, does not need to explicitly indicate the type of the variable, but the PHP variable is also of type, and the PHP variable contains the following 8 variables (three major categories)
A. Scalar type: boolean,integer,float (double), string
B. Composite type: Array,object
C. Special type: Resource,null
2.php the principle of using C language to implement variables
A. Variable storage structure
typedef struct _ZVAL_STRUCT zval;...struct _zval_struct {/ * Variable information */ zvalue_value value; /* The value of the stored variable is a reference count of the Union type */ zend_uint refcount__gc;/* variable, which defaults to 1*/ Zend_uchar type; /* Variable type, for Is_null, Is_bool, Is_long, is_double, is_string, Is_array, Is_object, and Is_resource */ Zend_uchar is_ref__ gc;/* Indicates whether it is a reference */};
B. Storage variables are worth Zvalue_value 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;
The union instead of the struct is used here to save memory space, assuming that a variable can only represent one type at a time
Reference: tipi open source Project Http://www.php-internals.com/book/?p=chapt03/03-01-00-variables-structure
http://www.bkjia.com/PHPjc/1111693.html www.bkjia.com true http://www.bkjia.com/PHPjc/1111693.html techarticle PHP variable principle, PHP variable 1.php as a weakly typed language, do not need to explicitly indicate the type of variable, but the PHP variable is also a type, PHP variable contains the following 8 kinds of variables (three big ...