PHP kernel study static variable _php tutorial

Source: Internet
Author: User
Static variable it can be a static global variable, if not called unset, then this static variable will persist until the program exits by Zend Memory management to release it can be a static local variable: defined in a function, after the function is executed, the static variable does not disappear it can be a static member variable: defined in the class , which can be shared among objects of all classes, such as "Static" {return t_static;} is a macro then open ZEND/ZEND_LANGUAGE_PARESER.L search t_static find code t_static static_var_list '; ' Follow up Static_va R_list Find Code static_var_list:static_var_list ', ' t_variable {zend_do_fetch_static_variable (&$3, NULL, ZEND_FETCH_ STATIC tsrmls_cc); } | Static_var_list ', ' t_variable ' = ' static_scalar {zend_do_fetch_static_variable (&$3, &$5, ZEND_FETCH_STATIC TSRMLS_CC); } | t_variable {zend_do_fetch_static_variable (&$1, NULL, zend_fetch_static tsrmls_cc);} | T_variable ' = ' static_scalar {zend_do_fetch_static_variable (&$1, &$3, zend_fetch_static TSRMLS_CC);}; Here it is. It is parsed by the PHP parser into the above code zend_do_fetch_static_variable this function is it in the ZEND/ZEND_COMPILE.C definition code as follows void Zend_do_fetch_static_ Variable (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); Request 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 the static variable alloc_hashtable (CG (Active_op_array)->static_variables); /Initialize 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 onThe fact, the default fetch is Bp_var_w */www.2cto.com if (Fetch_type = = zend_fetch_lexical) {Znode dummy; zend_do_b Egin_variable_parse (Tsrmls_c); Zend_do_assign (&dummy, &lval, &result tsrmls_cc); Zend_do_free (&dummy tsrmls_cc); } else {zend_do_assign_ref (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); */ }

http://www.bkjia.com/PHPjc/477784.html www.bkjia.com true http://www.bkjia.com/PHPjc/477784.html techarticle static variable It can be a static global variable, if not called unset, then this static variable will persist until the program exits by Zend Memory management to release it can be static local ...

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