/* {{{get_var_name * * This extension requires PHP >= 5.1 * Due to PHP 5.1 introduced compiled variable * * Export a get_var_name function in PHP space. * Echo get_var_name ($var _name); Expect:var_name * Echo get_var_name ($lineno =100); Expect:lineno */ Php_function (Get_var_name) { int Len; Char *STRG = ""; if (Zend_num_args () < 1) { Return } /* Show all compilation variables int i; Zend_compiled_variable *vars = EG (Active_op_array)->vars; for (i=0; i < EG (active_op_array)->last_var; ++i) {//Last_var index of the last compiled variable spprintf (&STRG, 0, "%s\\nvar:%s\\n", STRG, EG (Active_op_array)->vars[i].name); ++vars; } */ Zend_op *pre_opline_ptr = *eg (opline_ptr); pre_opline_ptr--; This type of invocation is supported: get_var_name ($a = "VALUE"); Expect:a This adds the ability to correctly return the name of the variable in the case of assignment, and if the method parameter is assigned, the compiled opcode will be send_var before the There is a zend_assign operation, and the return value of the zend_assign operation is used. For example: $c = $d + 1; The return value of $d + 1 is used. You'll be able to confirm Is the previous method of invocation Zend_op *pre_pre_online_ptr = pre_opline_ptr-1; if (pre_pre_online_ptr && pre_pre_online_ptr->opcode = = Zend_assign &&! Pre_pre_online_ptr->result.u.ea.type & ext_type_unused)) { Get variable information by assigning a value before the Zend_op Pre_opline_ptr = pre_pre_online_ptr; } int index; such as Get_var_name ($name); At this time Send_var opcode op1 operand type is IS_CV that is Compiled Variable Only compiled variable is the direct storage index. PHP >= 5.1 if (Pre_opline_ptr->op1.op_type = = IS_CV) { index = pre_opline_ptr->op1.u.var; } else { Please refer to VLD source code $VLD _src/srm_oparray.c line:320 vld_dump_znode function index = pre_opline_ptr->op1.u.var/sizeof (temp_variable); } zend_compiled_variable var = EG (Active_op_array)->vars[index]; Len = spprintf (&STRG, 0, "%s", STRG, Var.name); Return_stringl (STRG, Len, 0); } /* }}} */ |