Home >Backend Development >PHP Tutorial >PHP variable principle, PHP variable_PHP tutorial

PHP variable principle, PHP variable_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-12 08:56:38761browse

PHP variable principle, php variables

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1111693.htmlTechArticlephp variable principle, php variable 1. As a weakly typed language, php does not need to explicitly specify variables Type, but php variables also have types. php variables include the following 8 types of variables (three major...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn