Php variable principle, php variable

Source: Internet
Author: User

Php variable principle, php variable

1. As a weak type language, php does not need to explicitly specify the type of the variable, but php variables are also of the type. php variables include the following eight variables (three categories)

A. scalar type: boolean, integer, float (double), string

B. Composite Type: array, object

C. Special Type: resource, null

2. How php uses C language to implement Variables

A. Variable Storage Structure

Typedef struct _ zval_struct zval ;... struct _ zval_struct {/* Variable information */zvalue_value value;/* store the Variable value, which is a union type */zend_uint refcount _ gc;/* Reference count of the Variable, the default value is 1 */zend_uchar type;/* variable type, which is one of 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. The stored variable is 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;

Here union is used instead of struct to save memory space, so 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

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.