PHP variable principle, PHP variable _php tutorial

Source: Internet
Author: User

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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.