PHP kernel research static variables

Source: Internet
Author: User
Static variables can be static global variables. If unset is not called, the static variables will always exist until the program exits and is managed by Zend memory to release them. it can be static local variables: as defined in the function, after the function is executed, the static variable will not disappear. it can be a static member change... "/> SyntaxHighlighter. all (); static variables can be static global variables. If unset is not called, this static variable will always exist, it is not managed by Zend memory until the program Exits. it can be a static local variable. it is defined in the function. after the function is executed, the static variable will not disappear. it can be a static member variable: defined in the class, it can be shared among all class objects such "Static" {return T_STATIC;} is a macro. open zend/zend_language_pareser.l and search T_STATIC to find the code T_STATIC static_var_list '. follow static_var_list to find the code static_var_list ', 't_variable {variable (& $3, NULL, ZEND_FETCH_STATIC TSRMLS_CC);} | static_var_list ', 't_variable' = 'static_scalar {variable (& $3, & $5, ZEND_FETCH_STATIC TSRMLS_CC);} | T_VARIABLE {zend _ Substring (& $1, NULL, ZEND_FETCH_STATIC TSRMLS_CC) ;}| T_VARIABLE '= 'static_scalar {substring (& $1, & $3, ZEND_FETCH_STATIC TSRMLS_CC );}; that's it .. it is parsed by the PHP syntax analysis program into the above code zend_do_fetch_static_variable. it defines the following code in zend/zend_compile.c: void merge (znode * varname, const znode * static_assignment, int fetch_type TSRMLS_DC) {zval * tmp; // A temporary variable Zend_op * opline; znode lval; znode result; ALLOC_ZVAL (tmp); // apply for a piece of memory if (static_assignment) {* tmp = static_assignment-> u. constant;} else {INIT_ZVAL (* tmp);} if (! CG (active_op_array)-> static_variables) {// initialize the HASH key value of static variables ALLOC_HASHTABLE (CG (active_op_array)-> static_variables); // initialize the HASH value zend_hash_init (CG (active_op_array) -> static_variables, 2, NULL, ZVAL_PTR_DTOR, 0);} zend_hash_update (CG (active_op_array)-> static_variables, varname-> u. constant. value. str. val, varname-> u. constant. value. str. len + 1, & tmp, sizeof (zval *), NULL); if (varname-> op_type = IS_CONST ){ If (Z_TYPE (varname-> u. constant )! = IS_STRING) {convert_to_string (& varname-> u. constant) ;}} opline = get_next_op (CG (active_op_array) TSRMLS_CC); opline-> result. op_type = IS_VAR; opline-> result. u. EA. type = 0; opline-> result. u. var = get_temporary_variable (CG (active_op_array); opline-> op1 = * varname; SET_UNUSED (opline-> op2); opline-> op2.u. EA. type = ZEND_FETCH_STATIC; result = opline-> result; if (varname-> op_type = IS_CONST) {zval_copy_ctor (& varname-> u. constant);} fetch_simple_variable (& lval, varname, 0 TSRMLS_CC);/* Relies on the fact that the default fetch is BP_VAR_W */www.2cto.com if (fetch_type = bytes) {znode dummy; empty (TSRMLS_C); zend_do_assign (& dummy, & lval, & result TSRMLS_CC); zend_do_free (& dummy TSRMLS_CC);} else {empty (NULL, & lval, & result TSRMLS_CC);} CG (active_op_array)-> opcodes [CG (active_op_array)-> last-1]. result. u. EA. type | = EXT_TYPE_UNUSED;/* zval_dtor (& varname-> u. constant );*/}

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.