PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - Zend - zend_compile.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 2843 3036 93.6 %
Date: 2014-04-18 Functions: 185 188 98.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2013 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        | 
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #include <zend_language_parser.h>
      23             : #include "zend.h"
      24             : #include "zend_compile.h"
      25             : #include "zend_constants.h"
      26             : #include "zend_llist.h"
      27             : #include "zend_API.h"
      28             : #include "zend_exceptions.h"
      29             : #include "tsrm_virtual_cwd.h"
      30             : 
      31             : #ifdef ZEND_MULTIBYTE
      32             : #include "zend_multibyte.h"
      33             : #endif /* ZEND_MULTIBYTE */
      34             : 
      35             : ZEND_API zend_op_array *(*zend_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC);
      36             : ZEND_API zend_op_array *(*zend_compile_string)(zval *source_string, char *filename TSRMLS_DC);
      37             : 
      38             : #ifndef ZTS
      39             : ZEND_API zend_compiler_globals compiler_globals;
      40             : ZEND_API zend_executor_globals executor_globals;
      41             : #endif
      42             : 
      43       16767 : static void zend_duplicate_property_info(zend_property_info *property_info) /* {{{ */
      44             : {
      45       16767 :         property_info->name = estrndup(property_info->name, property_info->name_length);
      46       16767 :         if (property_info->doc_comment) {
      47           6 :                 property_info->doc_comment = estrndup(property_info->doc_comment, property_info->doc_comment_len);
      48             :         }
      49       16767 : }
      50             : /* }}} */
      51             : 
      52             : 
      53     2920491 : static void zend_duplicate_property_info_internal(zend_property_info *property_info) /* {{{ */
      54             : {
      55     2920491 :         property_info->name = zend_strndup(property_info->name, property_info->name_length);
      56     2920491 : }
      57             : /* }}} */
      58             : 
      59             : 
      60       18743 : static void zend_destroy_property_info(zend_property_info *property_info) /* {{{ */
      61             : {
      62       18743 :         efree(property_info->name);
      63       18743 :         if (property_info->doc_comment) {
      64          48 :                 efree(property_info->doc_comment);
      65             :         }
      66       18743 : }
      67             : /* }}} */
      68             : 
      69             : 
      70     4204452 : static void zend_destroy_property_info_internal(zend_property_info *property_info) /* {{{ */
      71             : {
      72     4204452 :         free(property_info->name);
      73     4204452 : }
      74             : /* }}} */
      75             : 
      76       26039 : static void build_runtime_defined_function_key(zval *result, const char *name, int name_length TSRMLS_DC) /* {{{ */
      77             : {
      78             :         char char_pos_buf[32];
      79             :         uint char_pos_len;
      80             :         char *filename;
      81             : 
      82       26039 :         char_pos_len = zend_sprintf(char_pos_buf, "%p", LANG_SCNG(yy_text));
      83       26039 :         if (CG(active_op_array)->filename) {
      84       26039 :                 filename = CG(active_op_array)->filename;
      85             :         } else {
      86           0 :                 filename = "-";
      87             :         }
      88             : 
      89             :         /* NULL, name length, filename length, last accepting char position length */
      90       26039 :         result->value.str.len = 1+name_length+strlen(filename)+char_pos_len;
      91             : #ifdef ZEND_MULTIBYTE
      92             :         /* must be binary safe */
      93             :         result->value.str.val = (char *) safe_emalloc(result->value.str.len, 1, 1);
      94             :         result->value.str.val[0] = '\0';
      95             :         sprintf(result->value.str.val+1, "%s%s%s", name, filename, char_pos_buf);
      96             : #else
      97       26039 :         zend_spprintf(&result->value.str.val, 0, "%c%s%s%s", '\0', name, filename, char_pos_buf);
      98             : #endif /* ZEND_MULTIBYTE */
      99       26039 :         result->type = IS_STRING;
     100             :         Z_SET_REFCOUNT_P(result, 1);
     101       26039 : }
     102             : /* }}} */
     103             : 
     104             : 
     105      174249 : int zend_auto_global_arm(zend_auto_global *auto_global TSRMLS_DC) /* {{{ */
     106             : {
     107      174249 :         auto_global->armed = (auto_global->auto_global_callback ? 1 : 0);
     108      174249 :         return 0;
     109             : }
     110             : /* }}} */
     111             : 
     112             : 
     113       57964 : ZEND_API int zend_auto_global_disable_jit(const char *varname, zend_uint varname_length TSRMLS_DC) /* {{{ */
     114             : {
     115             :         zend_auto_global *auto_global;
     116             : 
     117       57964 :         if (zend_hash_find(CG(auto_globals), varname, varname_length+1, (void **) &auto_global)==FAILURE) {
     118           0 :                 return FAILURE;
     119             :         }
     120       57964 :         auto_global->armed = 0;
     121       57964 :         return SUCCESS;
     122             : }
     123             : /* }}} */
     124             : 
     125             : 
     126       19361 : static void init_compiler_declarables(TSRMLS_D) /* {{{ */
     127             : {
     128       19361 :         Z_TYPE(CG(declarables).ticks) = IS_LONG;
     129       19361 :         Z_LVAL(CG(declarables).ticks) = 0;
     130       19361 : }
     131             : /* }}} */
     132             : 
     133             : 
     134       19361 : void zend_init_compiler_data_structures(TSRMLS_D) /* {{{ */
     135             : {
     136       19361 :         zend_stack_init(&CG(bp_stack));
     137       19361 :         zend_stack_init(&CG(function_call_stack));
     138       19361 :         zend_stack_init(&CG(switch_cond_stack));
     139       19361 :         zend_stack_init(&CG(foreach_copy_stack));
     140       19361 :         zend_stack_init(&CG(object_stack));
     141       19361 :         zend_stack_init(&CG(declare_stack));
     142       19361 :         CG(active_class_entry) = NULL;
     143       19361 :         zend_llist_init(&CG(list_llist), sizeof(list_llist_element), NULL, 0);
     144       19361 :         zend_llist_init(&CG(dimension_llist), sizeof(int), NULL, 0);
     145       19361 :         zend_stack_init(&CG(list_stack));
     146       19361 :         CG(in_compilation) = 0;
     147       19361 :         CG(start_lineno) = 0;
     148       19361 :         CG(current_namespace) = NULL;
     149       19361 :         CG(in_namespace) = 0;
     150       19361 :         CG(has_bracketed_namespaces) = 0;
     151       19361 :         CG(current_import) = NULL;
     152       19361 :         init_compiler_declarables(TSRMLS_C);
     153       19361 :         zend_hash_apply(CG(auto_globals), (apply_func_t) zend_auto_global_arm TSRMLS_CC);
     154       19361 :         zend_stack_init(&CG(labels_stack));
     155       19361 :         CG(labels) = NULL;
     156             : 
     157             : #ifdef ZEND_MULTIBYTE
     158             :         CG(script_encoding_list) = NULL;
     159             :         CG(script_encoding_list_size) = 0;
     160             :         CG(internal_encoding) = NULL;
     161             :         CG(encoding_detector) = NULL;
     162             :         CG(encoding_converter) = NULL;
     163             :         CG(encoding_oddlen) = NULL;
     164             :         CG(encoding_declared) = 0;
     165             : #endif /* ZEND_MULTIBYTE */
     166       19361 : }
     167             : /* }}} */
     168             : 
     169             : 
     170       28565 : ZEND_API void file_handle_dtor(zend_file_handle *fh) /* {{{ */
     171             : {
     172             :         TSRMLS_FETCH();
     173             : 
     174       28565 :         zend_file_handle_dtor(fh TSRMLS_CC);
     175       28565 : }
     176             : /* }}} */
     177             : 
     178             : 
     179       19327 : void init_compiler(TSRMLS_D) /* {{{ */
     180             : {
     181       19327 :         CG(active_op_array) = NULL;
     182       19327 :         zend_init_compiler_data_structures(TSRMLS_C);
     183       19327 :         zend_init_rsrc_list(TSRMLS_C);
     184       19327 :         zend_hash_init(&CG(filenames_table), 5, NULL, (dtor_func_t) free_estring, 0);
     185       19327 :         zend_llist_init(&CG(open_files), sizeof(zend_file_handle), (void (*)(void *)) file_handle_dtor, 0);
     186       19327 :         CG(unclean_shutdown) = 0;
     187       19327 : }
     188             : /* }}} */
     189             : 
     190             : 
     191       19362 : void shutdown_compiler(TSRMLS_D) /* {{{ */
     192             : {
     193       19362 :         zend_stack_destroy(&CG(bp_stack));
     194       19362 :         zend_stack_destroy(&CG(function_call_stack));
     195       19362 :         zend_stack_destroy(&CG(switch_cond_stack));
     196       19362 :         zend_stack_destroy(&CG(foreach_copy_stack));
     197       19362 :         zend_stack_destroy(&CG(object_stack));
     198       19362 :         zend_stack_destroy(&CG(declare_stack));
     199       19362 :         zend_stack_destroy(&CG(list_stack));
     200       19362 :         zend_hash_destroy(&CG(filenames_table));
     201       19362 :         zend_llist_destroy(&CG(open_files));
     202       19362 :         zend_stack_destroy(&CG(labels_stack));
     203             : 
     204             : #ifdef ZEND_MULTIBYTE
     205             :         if (CG(script_encoding_list)) {
     206             :                 efree(CG(script_encoding_list));
     207             :         }
     208             : #endif /* ZEND_MULTIBYTE */
     209       19362 : }
     210             : /* }}} */
     211             : 
     212             : 
     213       29672 : ZEND_API char *zend_set_compiled_filename(const char *new_compiled_filename TSRMLS_DC) /* {{{ */
     214             : {
     215             :         char **pp, *p;
     216       29672 :         int length = strlen(new_compiled_filename);
     217             : 
     218       29672 :         if (zend_hash_find(&CG(filenames_table), new_compiled_filename, length+1, (void **) &pp) == SUCCESS) {
     219         879 :                 CG(compiled_filename) = *pp;
     220         879 :                 return *pp;
     221             :         }
     222       28793 :         p = estrndup(new_compiled_filename, length);
     223       28793 :         zend_hash_update(&CG(filenames_table), new_compiled_filename, length+1, &p, sizeof(char *), (void **) &pp);
     224       28793 :         CG(compiled_filename) = p;
     225       28793 :         return p;
     226             : }
     227             : /* }}} */
     228             : 
     229             : 
     230       29530 : ZEND_API void zend_restore_compiled_filename(char *original_compiled_filename TSRMLS_DC) /* {{{ */
     231             : {
     232       29530 :         CG(compiled_filename) = original_compiled_filename;
     233       29530 : }
     234             : /* }}} */
     235             : 
     236             : 
     237      111946 : ZEND_API char *zend_get_compiled_filename(TSRMLS_D) /* {{{ */
     238             : {
     239      111946 :         return CG(compiled_filename);
     240             : }
     241             : /* }}} */
     242             : 
     243             : 
     244       79481 : ZEND_API int zend_get_compiled_lineno(TSRMLS_D) /* {{{ */
     245             : {
     246       79481 :         return CG(zend_lineno);
     247             : }
     248             : /* }}} */
     249             : 
     250             : 
     251     2413122 : ZEND_API zend_bool zend_is_compiling(TSRMLS_D) /* {{{ */
     252             : {
     253     2413122 :         return CG(in_compilation);
     254             : }
     255             : /* }}} */
     256             : 
     257             : 
     258     1112603 : static zend_uint get_temporary_variable(zend_op_array *op_array) /* {{{ */
     259             : {
     260     1112603 :         return (op_array->T)++ * ZEND_MM_ALIGNED_SIZE(sizeof(temp_variable));
     261             : }
     262             : /* }}} */
     263             : 
     264      842932 : static int lookup_cv(zend_op_array *op_array, char* name, int name_len) /* {{{ */
     265             : {
     266      842932 :         int i = 0;
     267      842932 :         ulong hash_value = zend_inline_hash_func(name, name_len+1);
     268             : 
     269  2154541110 :         while (i < op_array->last_var) {
     270  2154558817 :                 if (op_array->vars[i].hash_value == hash_value &&
     271      567857 :                     op_array->vars[i].name_len == name_len &&
     272      567857 :                     strcmp(op_array->vars[i].name, name) == 0) {
     273      567857 :                   efree(name);
     274      567857 :                   return i;
     275             :                 }
     276  2152855246 :                 i++;
     277             :         }
     278      275075 :         i = op_array->last_var;
     279      275075 :         op_array->last_var++;
     280      275075 :         if (op_array->last_var > op_array->size_var) {
     281       54606 :                 op_array->size_var += 16; /* FIXME */
     282       54606 :                 op_array->vars = erealloc(op_array->vars, op_array->size_var*sizeof(zend_compiled_variable));
     283             :         }
     284      275075 :         op_array->vars[i].name = name; /* estrndup(name, name_len); */
     285      275075 :         op_array->vars[i].name_len = name_len;
     286      275075 :         op_array->vars[i].hash_value = hash_value;
     287      275075 :         return i;
     288             : }
     289             : /* }}} */
     290             : 
     291             : 
     292       89216 : void zend_do_binary_op(zend_uchar op, znode *result, const znode *op1, const znode *op2 TSRMLS_DC) /* {{{ */
     293             : {
     294       89216 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     295             : 
     296       89216 :         opline->opcode = op;
     297       89216 :         opline->result.op_type = IS_TMP_VAR;
     298       89216 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
     299       89216 :         opline->op1 = *op1;
     300       89216 :         opline->op2 = *op2;
     301       89216 :         *result = opline->result;
     302       89216 : }
     303             : /* }}} */
     304             : 
     305       42967 : void zend_do_unary_op(zend_uchar op, znode *result, const znode *op1 TSRMLS_DC) /* {{{ */
     306             : {
     307       42967 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     308             : 
     309       42967 :         opline->opcode = op;
     310       42967 :         opline->result.op_type = IS_TMP_VAR;
     311       42967 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
     312       42967 :         opline->op1 = *op1;
     313       42967 :         *result = opline->result;
     314       42967 :         SET_UNUSED(opline->op2);
     315       42967 : }
     316             : /* }}} */
     317             : 
     318             : #define MAKE_NOP(opline)        { opline->opcode = ZEND_NOP;  memset(&opline->result,0,sizeof(znode)); memset(&opline->op1,0,sizeof(znode)); memset(&opline->op2,0,sizeof(znode)); opline->result.op_type=opline->op1.op_type=opline->op2.op_type=IS_UNUSED;  }
     319             : 
     320             : 
     321       16270 : static void zend_do_op_data(zend_op *data_op, const znode *value TSRMLS_DC) /* {{{ */
     322             : {
     323       16270 :         data_op->opcode = ZEND_OP_DATA;
     324       16270 :         data_op->op1 = *value;
     325       16270 :         SET_UNUSED(data_op->op2);
     326       16270 : }
     327             : /* }}} */
     328             : 
     329        3757 : void zend_do_binary_assign_op(zend_uchar op, znode *result, const znode *op1, const znode *op2 TSRMLS_DC) /* {{{ */
     330             : {
     331        3757 :         int last_op_number = get_next_op_number(CG(active_op_array));
     332        3757 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     333             : 
     334        3757 :         if (last_op_number > 0) {
     335        3757 :                 zend_op *last_op = &CG(active_op_array)->opcodes[last_op_number-1];
     336             : 
     337        3757 :                 switch (last_op->opcode) {
     338             :                         case ZEND_FETCH_OBJ_RW:
     339          44 :                                 last_op->opcode = op;
     340          44 :                                 last_op->extended_value = ZEND_ASSIGN_OBJ;
     341             : 
     342          44 :                                 zend_do_op_data(opline, op2 TSRMLS_CC);
     343          44 :                                 SET_UNUSED(opline->result);
     344          44 :                                 *result = last_op->result;
     345          44 :                                 return;
     346             :                         case ZEND_FETCH_DIM_RW:
     347          39 :                                 last_op->opcode = op;
     348          39 :                                 last_op->extended_value = ZEND_ASSIGN_DIM;
     349             : 
     350          39 :                                 zend_do_op_data(opline, op2 TSRMLS_CC);
     351          39 :                                 opline->op2.u.var = get_temporary_variable(CG(active_op_array));
     352          39 :                                 opline->op2.u.EA.type = 0;
     353          39 :                                 opline->op2.op_type = IS_VAR;
     354          39 :                                 SET_UNUSED(opline->result);
     355          39 :                                 *result = last_op->result;
     356          39 :                                 return;
     357             :                         default:
     358             :                                 break;
     359             :                 }
     360             :         }
     361             : 
     362        3674 :         opline->opcode = op;
     363        3674 :         opline->op1 = *op1;
     364        3674 :         opline->op2 = *op2;
     365        3674 :         opline->result.op_type = IS_VAR;
     366        3674 :         opline->result.u.EA.type = 0;
     367        3674 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
     368        3674 :         *result = opline->result;
     369             : }
     370             : /* }}} */
     371             : 
     372      867814 : void fetch_simple_variable_ex(znode *result, znode *varname, int bp, zend_uchar op TSRMLS_DC) /* {{{ */
     373             : {
     374             :         zend_op opline;
     375             :         zend_op *opline_ptr;
     376             :         zend_llist *fetch_list_ptr;
     377             : 
     378      867814 :         if (varname->op_type == IS_CONST) {
     379      867634 :                 if (Z_TYPE(varname->u.constant) != IS_STRING) {
     380           0 :                         convert_to_string(&varname->u.constant);
     381             :                 }
     382     2699148 :                 if (!zend_is_auto_global(varname->u.constant.value.str.val, varname->u.constant.value.str.len TSRMLS_CC) &&
     383             :                     !(varname->u.constant.value.str.len == (sizeof("this")-1) &&
     384      174951 :                       !memcmp(varname->u.constant.value.str.val, "this", sizeof("this"))) &&
     385      846234 :                     (CG(active_op_array)->last == 0 ||
     386      810329 :                      CG(active_op_array)->opcodes[CG(active_op_array)->last-1].opcode != ZEND_BEGIN_SILENCE)) {
     387      840659 :                         result->op_type = IS_CV;
     388      840659 :                         result->u.var = lookup_cv(CG(active_op_array), varname->u.constant.value.str.val, varname->u.constant.value.str.len);
     389      840659 :                         result->u.EA.type = 0;
     390      840659 :                         varname->u.constant.value.str.val = CG(active_op_array)->vars[result->u.var].name;
     391      840659 :                         return;
     392             :                 }
     393             :         }
     394             : 
     395       27155 :         if (bp) {
     396       27141 :                 opline_ptr = &opline;
     397       27141 :                 init_op(opline_ptr TSRMLS_CC);
     398             :         } else {
     399          14 :                 opline_ptr = get_next_op(CG(active_op_array) TSRMLS_CC);
     400             :         }
     401             : 
     402       27155 :         opline_ptr->opcode = op;
     403       27155 :         opline_ptr->result.op_type = IS_VAR;
     404       27155 :         opline_ptr->result.u.EA.type = 0;
     405       27155 :         opline_ptr->result.u.var = get_temporary_variable(CG(active_op_array));
     406       27155 :         opline_ptr->op1 = *varname;
     407       27155 :         *result = opline_ptr->result;
     408       27155 :         SET_UNUSED(opline_ptr->op2);
     409             : 
     410       27155 :         opline_ptr->op2.u.EA.type = ZEND_FETCH_LOCAL;
     411       27155 :         if (varname->op_type == IS_CONST && varname->u.constant.type == IS_STRING) {
     412       26975 :                 if (zend_is_auto_global(varname->u.constant.value.str.val, varname->u.constant.value.str.len TSRMLS_CC)) {
     413       17499 :                         opline_ptr->op2.u.EA.type = ZEND_FETCH_GLOBAL;
     414             :                 }
     415             :         }
     416             : 
     417       27155 :         if (bp) {
     418       27141 :                 zend_stack_top(&CG(bp_stack), (void **) &fetch_list_ptr);
     419       27141 :                 zend_llist_add_element(fetch_list_ptr, opline_ptr);
     420             :         }
     421             : }
     422             : /* }}} */
     423             : 
     424      867804 : void fetch_simple_variable(znode *result, znode *varname, int bp TSRMLS_DC) /* {{{ */
     425             : {
     426             :         /* the default mode must be Write, since fetch_simple_variable() is used to define function arguments */
     427      867804 :         fetch_simple_variable_ex(result, varname, bp, ZEND_FETCH_W TSRMLS_CC);
     428      867804 : }
     429             : /* }}} */
     430             : 
     431         341 : void zend_do_fetch_static_member(znode *result, znode *class_name TSRMLS_DC) /* {{{ */
     432             : {
     433             :         znode class_node;
     434             :         zend_llist *fetch_list_ptr;
     435             :         zend_llist_element *le;
     436             :         zend_op *opline_ptr;
     437             :         zend_op opline;
     438             : 
     439         341 :         zend_do_fetch_class(&class_node, class_name TSRMLS_CC);
     440         341 :         zend_stack_top(&CG(bp_stack), (void **) &fetch_list_ptr);
     441         341 :         if (result->op_type == IS_CV) {
     442         315 :                 init_op(&opline TSRMLS_CC);
     443             : 
     444         315 :                 opline.opcode = ZEND_FETCH_W;
     445         315 :                 opline.result.op_type = IS_VAR;
     446         315 :                 opline.result.u.EA.type = 0;
     447         315 :                 opline.result.u.var = get_temporary_variable(CG(active_op_array));
     448         315 :                 opline.op1.op_type = IS_CONST;
     449         315 :                 opline.op1.u.constant.type = IS_STRING;
     450         315 :                 opline.op1.u.constant.value.str.val = estrdup(CG(active_op_array)->vars[result->u.var].name);
     451         315 :                 opline.op1.u.constant.value.str.len = CG(active_op_array)->vars[result->u.var].name_len;
     452         315 :                 SET_UNUSED(opline.op2);
     453         315 :                 opline.op2 = class_node;
     454         315 :                 opline.op2.u.EA.type = ZEND_FETCH_STATIC_MEMBER;
     455         315 :                 *result = opline.result;
     456             : 
     457         315 :                 zend_llist_add_element(fetch_list_ptr, &opline);
     458             :         } else {
     459          26 :                 le = fetch_list_ptr->head;
     460             : 
     461          26 :                 opline_ptr = (zend_op *)le->data;
     462          51 :                 if (opline_ptr->opcode != ZEND_FETCH_W && opline_ptr->op1.op_type == IS_CV) {
     463          25 :                         init_op(&opline TSRMLS_CC);
     464          25 :                         opline.opcode = ZEND_FETCH_W;
     465          25 :                         opline.result.op_type = IS_VAR;
     466          25 :                         opline.result.u.EA.type = 0;
     467          25 :                         opline.result.u.var = get_temporary_variable(CG(active_op_array));
     468          25 :                         opline.op1.op_type = IS_CONST;
     469          25 :                         opline.op1.u.constant.type = IS_STRING;
     470          25 :                         opline.op1.u.constant.value.str.val = estrdup(CG(active_op_array)->vars[opline_ptr->op1.u.var].name);
     471          25 :                         opline.op1.u.constant.value.str.len = CG(active_op_array)->vars[opline_ptr->op1.u.var].name_len;
     472          25 :                         SET_UNUSED(opline.op2);
     473          25 :                         opline.op2 = class_node;
     474          25 :                         opline.op2.u.EA.type = ZEND_FETCH_STATIC_MEMBER;
     475          25 :                         opline_ptr->op1 = opline.result;
     476             : 
     477          25 :                         zend_llist_prepend_element(fetch_list_ptr, &opline);
     478             :                 } else {
     479           1 :                         opline_ptr->op2 = class_node;
     480           1 :                         opline_ptr->op2.u.EA.type = ZEND_FETCH_STATIC_MEMBER;
     481             :                 }
     482             :         }
     483         341 : }
     484             : /* }}} */
     485             : 
     486         958 : void fetch_array_begin(znode *result, znode *varname, znode *first_dim TSRMLS_DC) /* {{{ */
     487             : {
     488         958 :         fetch_simple_variable(result, varname, 1 TSRMLS_CC);
     489             : 
     490         958 :         fetch_array_dim(result, result, first_dim TSRMLS_CC);
     491         958 : }
     492             : /* }}} */
     493             : 
     494      153486 : void fetch_array_dim(znode *result, const znode *parent, const znode *dim TSRMLS_DC) /* {{{ */
     495             : {
     496             :         zend_op opline;
     497             :         zend_llist *fetch_list_ptr;
     498             : 
     499      153486 :         init_op(&opline TSRMLS_CC);
     500      153486 :         opline.opcode = ZEND_FETCH_DIM_W;       /* the backpatching routine assumes W */
     501      153486 :         opline.result.op_type = IS_VAR;
     502      153486 :         opline.result.u.EA.type = 0;
     503      153486 :         opline.result.u.var = get_temporary_variable(CG(active_op_array));
     504      153486 :         opline.op1 = *parent;
     505      153486 :         opline.op2 = *dim;
     506      153486 :         opline.extended_value = ZEND_FETCH_STANDARD;
     507      153486 :         *result = opline.result;
     508             : 
     509      153486 :         zend_stack_top(&CG(bp_stack), (void **) &fetch_list_ptr);
     510      153486 :         zend_llist_add_element(fetch_list_ptr, &opline);
     511      153486 : }
     512             : /* }}} */
     513             : 
     514          21 : void fetch_string_offset(znode *result, const znode *parent, const znode *offset TSRMLS_DC) /* {{{ */
     515             : {
     516          21 :         fetch_array_dim(result, parent, offset TSRMLS_CC);
     517          21 : }
     518             : /* }}} */
     519             : 
     520        3290 : void zend_do_print(znode *result, const znode *arg TSRMLS_DC) /* {{{ */
     521             : {
     522        3290 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     523             : 
     524        3290 :         opline->result.op_type = IS_TMP_VAR;
     525        3290 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
     526        3290 :         opline->opcode = ZEND_PRINT;
     527        3290 :         opline->op1 = *arg;
     528        3290 :         SET_UNUSED(opline->op2);
     529        3290 :         *result = opline->result;
     530        3290 : }
     531             : /* }}} */
     532             : 
     533       35398 : void zend_do_echo(const znode *arg TSRMLS_DC) /* {{{ */
     534             : {
     535       35398 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     536             : 
     537       35398 :         opline->opcode = ZEND_ECHO;
     538       35398 :         opline->op1 = *arg;
     539       35398 :         SET_UNUSED(opline->op2);
     540       35398 : }
     541             : /* }}} */
     542             : 
     543       16863 : void zend_do_abstract_method(const znode *function_name, znode *modifiers, const znode *body TSRMLS_DC) /* {{{ */
     544             : {
     545             :         char *method_type;
     546             : 
     547       16863 :         if (CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE) {
     548          80 :                 Z_LVAL(modifiers->u.constant) |= ZEND_ACC_ABSTRACT;
     549          80 :                 method_type = "Interface";
     550             :         } else {
     551       16783 :                 method_type = "Abstract";
     552             :         }
     553             : 
     554       16863 :         if (modifiers->u.constant.value.lval & ZEND_ACC_ABSTRACT) {
     555         121 :                 if(modifiers->u.constant.value.lval & ZEND_ACC_PRIVATE) {
     556           1 :                         zend_error(E_COMPILE_ERROR, "%s function %s::%s() cannot be declared private", method_type, CG(active_class_entry)->name, function_name->u.constant.value.str.val);
     557             :                 }
     558         120 :                 if (Z_LVAL(body->u.constant) == ZEND_ACC_ABSTRACT) {
     559         119 :                         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     560             : 
     561         119 :                         opline->opcode = ZEND_RAISE_ABSTRACT_ERROR;
     562         119 :                         SET_UNUSED(opline->op1);
     563         119 :                         SET_UNUSED(opline->op2);
     564             :                 } else {
     565             :                         /* we had code in the function body */
     566           1 :                         zend_error(E_COMPILE_ERROR, "%s function %s::%s() cannot contain body", method_type, CG(active_class_entry)->name, function_name->u.constant.value.str.val);
     567             :                 }
     568             :         } else {
     569       16742 :                 if (body->u.constant.value.lval == ZEND_ACC_ABSTRACT) {
     570           1 :                         zend_error(E_COMPILE_ERROR, "Non-abstract method %s::%s() must contain body", CG(active_class_entry)->name, function_name->u.constant.value.str.val);
     571             :                 }
     572             :         }
     573       16860 : }
     574             : /* }}} */
     575             : 
     576      201214 : static zend_bool opline_is_fetch_this(const zend_op *opline TSRMLS_DC) /* {{{ */
     577             : {
     578      271332 :         if ((opline->opcode == ZEND_FETCH_W) && (opline->op1.op_type == IS_CONST)
     579       27630 :                 && (opline->op1.u.constant.type == IS_STRING)
     580       27630 :                 && (opline->op1.u.constant.value.str.len == (sizeof("this")-1))
     581       14858 :                 && !memcmp(opline->op1.u.constant.value.str.val, "this", sizeof("this"))) {
     582        3899 :                 return 1;
     583             :         } else {
     584      197315 :                 return 0;
     585             :         }
     586             : }
     587             : /* }}} */
     588             : 
     589      181874 : void zend_do_assign(znode *result, znode *variable, const znode *value TSRMLS_DC) /* {{{ */
     590             : {
     591             :         int last_op_number;
     592             :         zend_op *opline;
     593             : 
     594      181874 :         if (value->op_type == IS_CV) {
     595             :                 zend_llist *fetch_list_ptr;
     596             : 
     597        5221 :                 zend_stack_top(&CG(bp_stack), (void **) &fetch_list_ptr);
     598        5221 :                 if (fetch_list_ptr && fetch_list_ptr->head) {
     599        2673 :                         opline = (zend_op *)fetch_list_ptr->head->data;
     600             : 
     601        6423 :                         if (opline->opcode == ZEND_FETCH_DIM_W &&
     602        1875 :                             opline->op1.op_type == IS_CV &&
     603        1875 :                             opline->op1.u.var == value->u.var) {
     604             : 
     605          14 :                                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     606          14 :                                 opline->opcode = ZEND_FETCH_R;
     607          14 :                                 opline->result.op_type = IS_VAR;
     608          14 :                                 opline->result.u.EA.type = 0;
     609          14 :                                 opline->result.u.var = get_temporary_variable(CG(active_op_array));
     610          14 :                                 opline->op1.op_type = IS_CONST;
     611          14 :                                 ZVAL_STRINGL(&opline->op1.u.constant,
     612             :                                         CG(active_op_array)->vars[value->u.var].name, 
     613             :                                         CG(active_op_array)->vars[value->u.var].name_len, 1);
     614          14 :                                 SET_UNUSED(opline->op2);
     615          14 :                                 opline->op2.u.EA.type = ZEND_FETCH_LOCAL;
     616          14 :                                 value = &opline->result;
     617             :                         }
     618             :                 }
     619             :         }
     620             : 
     621      181874 :         zend_do_end_variable_parse(variable, BP_VAR_W, 0 TSRMLS_CC);
     622             : 
     623      181874 :         last_op_number = get_next_op_number(CG(active_op_array));
     624      181874 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     625             : 
     626      181874 :         if (variable->op_type == IS_CV) {
     627      165518 :                 if (variable->u.var == CG(active_op_array)->this_var) {
     628           2 :                         zend_error(E_COMPILE_ERROR, "Cannot re-assign $this");
     629             :                 }
     630       16356 :         } else if (variable->op_type == IS_VAR) {
     631       16356 :                 int n = 0;
     632             : 
     633       32712 :                 while (last_op_number - n > 0) {
     634             :                         zend_op *last_op;
     635             : 
     636       16356 :                         last_op = &CG(active_op_array)->opcodes[last_op_number-n-1];
     637             : 
     638       32712 :                         if (last_op->result.op_type == IS_VAR &&
     639       16356 :                             last_op->result.u.var == variable->u.var) {
     640       16356 :                                 if (last_op->opcode == ZEND_FETCH_OBJ_W) {
     641        1618 :                                         if (n > 0) {
     642           0 :                                                 int opline_no = (opline-CG(active_op_array)->opcodes)/sizeof(*opline);
     643           0 :                                                 *opline = *last_op;
     644           0 :                                                 MAKE_NOP(last_op);
     645             :                                                 /* last_op = opline; */
     646           0 :                                                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     647             :                                                 /* get_next_op can realloc, we need to move last_op */
     648           0 :                                                 last_op = &CG(active_op_array)->opcodes[opline_no];
     649             :                                         }
     650        1618 :                                         last_op->opcode = ZEND_ASSIGN_OBJ;
     651        1618 :                                         zend_do_op_data(opline, value TSRMLS_CC);
     652        1618 :                                         SET_UNUSED(opline->result);
     653        1618 :                                         *result = last_op->result;
     654        1618 :                                         return;
     655       14738 :                                 } else if (last_op->opcode == ZEND_FETCH_DIM_W) {
     656       14569 :                                         if (n > 0) {
     657           0 :                                                 int opline_no = (opline-CG(active_op_array)->opcodes)/sizeof(*opline);
     658           0 :                                                 *opline = *last_op;
     659           0 :                                                 MAKE_NOP(last_op);
     660             :                                                 /* last_op = opline; */
     661             :                                                 /* TBFixed: this can realloc opcodes, leaving last_op pointing wrong */
     662           0 :                                                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     663             :                                                 /* get_next_op can realloc, we need to move last_op */
     664           0 :                                                 last_op = &CG(active_op_array)->opcodes[opline_no];
     665             :                                         }
     666       14569 :                                         last_op->opcode = ZEND_ASSIGN_DIM;
     667       14569 :                                         zend_do_op_data(opline, value TSRMLS_CC);
     668       14569 :                                         opline->op2.u.var = get_temporary_variable(CG(active_op_array));
     669       14569 :                                         opline->op2.u.EA.type = 0;
     670       14569 :                                         opline->op2.op_type = IS_VAR;
     671       14569 :                                         SET_UNUSED(opline->result);
     672       14569 :                                         *result = last_op->result;
     673       14569 :                                         return;
     674         169 :                                 } else if (opline_is_fetch_this(last_op TSRMLS_CC)) {
     675           0 :                                         zend_error(E_COMPILE_ERROR, "Cannot re-assign $this");
     676             :                                 } else {
     677         169 :                                         break;
     678             :                                 }
     679             :                         }
     680           0 :                         n++;
     681             :                 }
     682             :         }
     683             : 
     684      165685 :         opline->opcode = ZEND_ASSIGN;
     685      165685 :         opline->op1 = *variable;
     686      165685 :         opline->op2 = *value;
     687      165685 :         opline->result.op_type = IS_VAR;
     688      165685 :         opline->result.u.EA.type = 0;
     689      165685 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
     690      165685 :         *result = opline->result;
     691             : }
     692             : /* }}} */
     693             : 
     694      422694 : static inline zend_bool zend_is_function_or_method_call(const znode *variable) /* {{{ */
     695             : {
     696      422694 :         zend_uint type = variable->u.EA.type;
     697             : 
     698      422694 :         return  ((type & ZEND_PARSED_METHOD_CALL) || (type == ZEND_PARSED_FUNCTION_CALL));
     699             : }
     700             : /* }}} */
     701             : 
     702        7878 : void zend_do_assign_ref(znode *result, const znode *lvar, const znode *rvar TSRMLS_DC) /* {{{ */
     703             : {
     704             :         zend_op *opline;
     705             : 
     706        7878 :         if (lvar->op_type == IS_CV) {
     707        7696 :                 if (lvar->u.var == CG(active_op_array)->this_var) {
     708           1 :                         zend_error(E_COMPILE_ERROR, "Cannot re-assign $this");
     709             :                 }
     710         182 :         } else if (lvar->op_type == IS_VAR) {
     711         182 :                 int last_op_number = get_next_op_number(CG(active_op_array));
     712             : 
     713         182 :                 if (last_op_number > 0) {
     714         182 :                         opline = &CG(active_op_array)->opcodes[last_op_number-1];
     715         182 :                         if (opline_is_fetch_this(opline TSRMLS_CC)) {
     716           0 :                                 zend_error(E_COMPILE_ERROR, "Cannot re-assign $this");
     717             :                         }
     718             :                 }
     719             :         }
     720             : 
     721        7877 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     722        7877 :         opline->opcode = ZEND_ASSIGN_REF;
     723        7877 :         if (zend_is_function_or_method_call(rvar)) {
     724          40 :                 opline->extended_value = ZEND_RETURNS_FUNCTION;
     725        7837 :         } else if (rvar->u.EA.type & ZEND_PARSED_NEW) {
     726          10 :                 opline->extended_value = ZEND_RETURNS_NEW;
     727             :         } else {
     728        7827 :                 opline->extended_value = 0;
     729             :         }
     730        7877 :         if (result) {
     731         394 :                 opline->result.op_type = IS_VAR;
     732         394 :                 opline->result.u.EA.type = 0;
     733         394 :                 opline->result.u.var = get_temporary_variable(CG(active_op_array));
     734         394 :                 *result = opline->result;
     735             :         } else {
     736             :                 /* SET_UNUSED(opline->result); */
     737        7483 :                 opline->result.u.EA.type |= EXT_TYPE_UNUSED;
     738             :         }
     739        7877 :         opline->op1 = *lvar;
     740        7877 :         opline->op2 = *rvar;
     741        7877 : }
     742             : /* }}} */
     743             : 
     744       16683 : static inline void do_begin_loop(TSRMLS_D) /* {{{ */
     745             : {
     746             :         zend_brk_cont_element *brk_cont_element;
     747             :         int parent;
     748             : 
     749       16683 :         parent = CG(active_op_array)->current_brk_cont;
     750       16683 :         CG(active_op_array)->current_brk_cont = CG(active_op_array)->last_brk_cont;
     751       16683 :         brk_cont_element = get_next_brk_cont_element(CG(active_op_array));
     752       16683 :         brk_cont_element->start = get_next_op_number(CG(active_op_array));
     753       16683 :         brk_cont_element->parent = parent;
     754       16683 : }
     755             : /* }}} */
     756             : 
     757       16239 : static inline void do_end_loop(int cont_addr, int has_loop_var TSRMLS_DC) /* {{{ */
     758             : {
     759       16239 :         if (!has_loop_var) {
     760             :                 /* The start fileld is used to free temporary variables in case of exceptions.
     761             :                  * We won't try to free something of we don't have loop variable.
     762             :                  */
     763        5084 :                 CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].start = -1;
     764             :         }
     765       16239 :         CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].cont = cont_addr;
     766       16239 :         CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].brk = get_next_op_number(CG(active_op_array));
     767       16239 :         CG(active_op_array)->current_brk_cont = CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].parent;
     768       16239 : }
     769             : /* }}} */
     770             : 
     771        2818 : void zend_do_while_cond(const znode *expr, znode *close_bracket_token TSRMLS_DC) /* {{{ */
     772             : {
     773        2818 :         int while_cond_op_number = get_next_op_number(CG(active_op_array));
     774        2818 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     775             : 
     776        2818 :         opline->opcode = ZEND_JMPZ;
     777        2818 :         opline->op1 = *expr;
     778        2818 :         close_bracket_token->u.opline_num = while_cond_op_number;
     779        2818 :         SET_UNUSED(opline->op2);
     780             : 
     781        2818 :         do_begin_loop(TSRMLS_C);
     782        2818 :         INC_BPC(CG(active_op_array));
     783        2818 : }
     784             : /* }}} */
     785             : 
     786        2818 : void zend_do_while_end(const znode *while_token, const znode *close_bracket_token TSRMLS_DC) /* {{{ */
     787             : {
     788        2818 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     789             : 
     790             :         /* add unconditional jump */
     791        2818 :         opline->opcode = ZEND_JMP;
     792        2818 :         opline->op1.u.opline_num = while_token->u.opline_num;
     793        2818 :         SET_UNUSED(opline->op1);
     794        2818 :         SET_UNUSED(opline->op2);
     795             : 
     796             :         /* update while's conditional jmp */
     797        2818 :         CG(active_op_array)->opcodes[close_bracket_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array));
     798             : 
     799        2818 :         do_end_loop(while_token->u.opline_num, 0 TSRMLS_CC);
     800             : 
     801        2818 :         DEC_BPC(CG(active_op_array));
     802        2818 : }
     803             : /* }}} */
     804             : 
     805        1994 : void zend_do_for_cond(const znode *expr, znode *second_semicolon_token TSRMLS_DC) /* {{{ */
     806             : {
     807        1994 :         int for_cond_op_number = get_next_op_number(CG(active_op_array));
     808        1994 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     809             : 
     810        1994 :         opline->opcode = ZEND_JMPZNZ;
     811        1994 :         opline->op1 = *expr;  /* the conditional expression */
     812        1994 :         second_semicolon_token->u.opline_num = for_cond_op_number;
     813        1994 :         SET_UNUSED(opline->op2);
     814        1994 : }
     815             : /* }}} */
     816             : 
     817        1994 : void zend_do_for_before_statement(const znode *cond_start, const znode *second_semicolon_token TSRMLS_DC) /* {{{ */
     818             : {
     819        1994 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     820             : 
     821        1994 :         opline->opcode = ZEND_JMP;
     822        1994 :         opline->op1.u.opline_num = cond_start->u.opline_num;
     823        1994 :         CG(active_op_array)->opcodes[second_semicolon_token->u.opline_num].extended_value = get_next_op_number(CG(active_op_array));
     824        1994 :         SET_UNUSED(opline->op1);
     825        1994 :         SET_UNUSED(opline->op2);
     826             : 
     827        1994 :         do_begin_loop(TSRMLS_C);
     828             : 
     829        1994 :         INC_BPC(CG(active_op_array));
     830        1994 : }
     831             : /* }}} */
     832             : 
     833        1994 : void zend_do_for_end(const znode *second_semicolon_token TSRMLS_DC) /* {{{ */
     834             : {
     835        1994 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     836             : 
     837        1994 :         opline->opcode = ZEND_JMP;
     838        1994 :         opline->op1.u.opline_num = second_semicolon_token->u.opline_num+1;
     839        1994 :         CG(active_op_array)->opcodes[second_semicolon_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array));
     840        1994 :         SET_UNUSED(opline->op1);
     841        1994 :         SET_UNUSED(opline->op2);
     842             : 
     843        1994 :         do_end_loop(second_semicolon_token->u.opline_num+1, 0 TSRMLS_CC);
     844             : 
     845        1994 :         DEC_BPC(CG(active_op_array));
     846        1994 : }
     847             : /* }}} */
     848             : 
     849         457 : void zend_do_pre_incdec(znode *result, const znode *op1, zend_uchar op TSRMLS_DC) /* {{{ */
     850             : {
     851         457 :         int last_op_number = get_next_op_number(CG(active_op_array));
     852             :         zend_op *opline;
     853             : 
     854         457 :         if (last_op_number > 0) {
     855         457 :                 zend_op *last_op = &CG(active_op_array)->opcodes[last_op_number-1];
     856             : 
     857         457 :                 if (last_op->opcode == ZEND_FETCH_OBJ_RW) {
     858           9 :                         last_op->opcode = (op==ZEND_PRE_INC)?ZEND_PRE_INC_OBJ:ZEND_PRE_DEC_OBJ;
     859           9 :                         last_op->result.op_type = IS_VAR;
     860           9 :                         last_op->result.u.EA.type = 0;
     861           9 :                         last_op->result.u.var = get_temporary_variable(CG(active_op_array));
     862           9 :                         *result = last_op->result;
     863           9 :                         return;
     864             :                 }
     865             :         }
     866             : 
     867         448 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     868         448 :         opline->opcode = op;
     869         448 :         opline->op1 = *op1;
     870         448 :         SET_UNUSED(opline->op2);
     871         448 :         opline->result.op_type = IS_VAR;
     872         448 :         opline->result.u.EA.type = 0;
     873         448 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
     874         448 :         *result = opline->result;
     875             : }
     876             : /* }}} */
     877             : 
     878        5519 : void zend_do_post_incdec(znode *result, const znode *op1, zend_uchar op TSRMLS_DC) /* {{{ */
     879             : {
     880        5519 :         int last_op_number = get_next_op_number(CG(active_op_array));
     881             :         zend_op *opline;
     882             : 
     883        5519 :         if (last_op_number > 0) {
     884        5519 :                 zend_op *last_op = &CG(active_op_array)->opcodes[last_op_number-1];
     885             : 
     886        5519 :                 if (last_op->opcode == ZEND_FETCH_OBJ_RW) {
     887          45 :                         last_op->opcode = (op==ZEND_POST_INC)?ZEND_POST_INC_OBJ:ZEND_POST_DEC_OBJ;
     888          45 :                         last_op->result.op_type = IS_TMP_VAR;
     889          45 :                         last_op->result.u.var = get_temporary_variable(CG(active_op_array));
     890          45 :                         *result = last_op->result;
     891          45 :                         return;
     892             :                 }
     893             :         }
     894             : 
     895        5474 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     896        5474 :         opline->opcode = op;
     897        5474 :         opline->op1 = *op1;
     898        5474 :         SET_UNUSED(opline->op2);
     899        5474 :         opline->result.op_type = IS_TMP_VAR;
     900        5474 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
     901        5474 :         *result = opline->result;
     902             : }
     903             : /* }}} */
     904             : 
     905       82693 : void zend_do_if_cond(const znode *cond, znode *closing_bracket_token TSRMLS_DC) /* {{{ */
     906             : {
     907       82693 :         int if_cond_op_number = get_next_op_number(CG(active_op_array));
     908       82693 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     909             : 
     910       82693 :         opline->opcode = ZEND_JMPZ;
     911       82693 :         opline->op1 = *cond;
     912       82693 :         closing_bracket_token->u.opline_num = if_cond_op_number;
     913       82693 :         SET_UNUSED(opline->op2);
     914       82693 :         INC_BPC(CG(active_op_array));
     915       82693 : }
     916             : /* }}} */
     917             : 
     918       82692 : void zend_do_if_after_statement(const znode *closing_bracket_token, unsigned char initialize TSRMLS_DC) /* {{{ */
     919             : {
     920       82692 :         int if_end_op_number = get_next_op_number(CG(active_op_array));
     921       82692 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     922             :         zend_llist *jmp_list_ptr;
     923             : 
     924       82692 :         opline->opcode = ZEND_JMP;
     925             :         /* save for backpatching */
     926       82692 :         if (initialize) {
     927             :                 zend_llist jmp_list;
     928             : 
     929       80886 :                 zend_llist_init(&jmp_list, sizeof(int), NULL, 0);
     930       80886 :                 zend_stack_push(&CG(bp_stack), (void *) &jmp_list, sizeof(zend_llist));
     931             :         }
     932       82692 :         zend_stack_top(&CG(bp_stack), (void **) &jmp_list_ptr);
     933       82692 :         zend_llist_add_element(jmp_list_ptr, &if_end_op_number);
     934             : 
     935       82692 :         CG(active_op_array)->opcodes[closing_bracket_token->u.opline_num].op2.u.opline_num = if_end_op_number+1;
     936       82692 :         SET_UNUSED(opline->op1);
     937       82692 :         SET_UNUSED(opline->op2);
     938       82692 : }
     939             : /* }}} */
     940             : 
     941       82941 : void zend_do_if_end(TSRMLS_D) /* {{{ */
     942             : {
     943       82941 :         int next_op_number = get_next_op_number(CG(active_op_array));
     944             :         zend_llist *jmp_list_ptr;
     945             :         zend_llist_element *le;
     946             : 
     947       82941 :         zend_stack_top(&CG(bp_stack), (void **) &jmp_list_ptr);
     948      169750 :         for (le=jmp_list_ptr->head; le; le = le->next) {
     949       86809 :                 CG(active_op_array)->opcodes[*((int *) le->data)].op1.u.opline_num = next_op_number;
     950             :         }
     951       82941 :         zend_llist_destroy(jmp_list_ptr);
     952       82941 :         zend_stack_del_top(&CG(bp_stack));
     953       82941 :         DEC_BPC(CG(active_op_array));
     954       82941 : }
     955             : /* }}} */
     956             : 
     957      206930 : void zend_check_writable_variable(const znode *variable) /* {{{ */
     958             : {
     959      206930 :         zend_uint type = variable->u.EA.type;
     960             : 
     961      206930 :         if (type & ZEND_PARSED_METHOD_CALL) {
     962           1 :                 zend_error(E_COMPILE_ERROR, "Can't use method return value in write context");
     963             :         }
     964      206929 :         if (type == ZEND_PARSED_FUNCTION_CALL) {
     965           1 :                 zend_error(E_COMPILE_ERROR, "Can't use function return value in write context");
     966             :         }
     967      206928 : }
     968             : /* }}} */
     969             : 
     970     1082554 : void zend_do_begin_variable_parse(TSRMLS_D) /* {{{ */
     971             : {
     972             :         zend_llist fetch_list;
     973             : 
     974     1082554 :         zend_llist_init(&fetch_list, sizeof(zend_op), NULL, 0);
     975     1082554 :         zend_stack_push(&CG(bp_stack), (void *) &fetch_list, sizeof(zend_llist));
     976     1082554 : }
     977             : /* }}} */
     978             : 
     979     1082535 : void zend_do_end_variable_parse(znode *variable, int type, int arg_offset TSRMLS_DC) /* {{{ */
     980             : {
     981             :         zend_llist *fetch_list_ptr;
     982             :         zend_llist_element *le;
     983     1082535 :         zend_op *opline = NULL;
     984             :         zend_op *opline_ptr;
     985     1082535 :         zend_uint this_var = -1;
     986             : 
     987     1082535 :         zend_stack_top(&CG(bp_stack), (void **) &fetch_list_ptr);
     988             : 
     989     1082535 :         le = fetch_list_ptr->head;
     990             : 
     991             :         /* TODO: $foo->x->y->z = 1 should fetch "x" and "y" for R or RW, not just W */
     992             : 
     993     1082535 :         if (le) {
     994      195613 :                 opline_ptr = (zend_op *)le->data;
     995      195613 :                 if (opline_is_fetch_this(opline_ptr TSRMLS_CC)) {
     996             :                         /* convert to FETCH_?(this) into IS_CV */
     997         748 :                         if (CG(active_op_array)->last == 0 ||
     998         215 :                             CG(active_op_array)->opcodes[CG(active_op_array)->last-1].opcode != ZEND_BEGIN_SILENCE) {
     999             : 
    1000         266 :                                 this_var = opline_ptr->result.u.var;
    1001         266 :                                 if (CG(active_op_array)->this_var == -1) {
    1002         209 :                                         CG(active_op_array)->this_var = lookup_cv(CG(active_op_array), Z_STRVAL(opline_ptr->op1.u.constant), Z_STRLEN(opline_ptr->op1.u.constant));
    1003             :                                 } else {
    1004          57 :                                         efree(Z_STRVAL(opline_ptr->op1.u.constant));
    1005             :                                 }
    1006         266 :                                 le = le->next;
    1007         532 :                                 if (variable->op_type == IS_VAR &&
    1008         266 :                                     variable->u.var == this_var) {
    1009         262 :                                         variable->op_type = IS_CV;
    1010         262 :                                         variable->u.var = CG(active_op_array)->this_var;
    1011             :                                 }
    1012           1 :                         } else if (CG(active_op_array)->this_var == -1) {
    1013           1 :                                 CG(active_op_array)->this_var = lookup_cv(CG(active_op_array), estrndup("this", sizeof("this")-1), sizeof("this")-1);
    1014             :                         }
    1015             :                 }
    1016             : 
    1017      612318 :                 while (le) {
    1018      221097 :                         opline_ptr = (zend_op *)le->data;
    1019      221097 :                         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1020      221097 :                         memcpy(opline, opline_ptr, sizeof(zend_op));
    1021      247347 :                         if (opline->op1.op_type == IS_VAR &&
    1022       26250 :                             opline->op1.u.var == this_var) {
    1023           4 :                                 opline->op1.op_type = IS_CV;
    1024           4 :                                 opline->op1.u.var = CG(active_op_array)->this_var;
    1025             :                         }
    1026      221097 :                         switch (type) {
    1027             :                                 case BP_VAR_R:
    1028      114545 :                                         if (opline->opcode == ZEND_FETCH_DIM_W && opline->op2.op_type == IS_UNUSED) {
    1029           3 :                                                 zend_error(E_COMPILE_ERROR, "Cannot use [] for reading");
    1030             :                                         }
    1031      114542 :                                         opline->opcode -= 3;
    1032      114542 :                                         break;
    1033             :                                 case BP_VAR_W:
    1034       90659 :                                         break;
    1035             :                                 case BP_VAR_RW:
    1036        1216 :                                         opline->opcode += 3;
    1037        1216 :                                         break;
    1038             :                                 case BP_VAR_IS:
    1039       13902 :                                         if (opline->opcode == ZEND_FETCH_DIM_W && opline->op2.op_type == IS_UNUSED) {
    1040           1 :                                                 zend_error(E_COMPILE_ERROR, "Cannot use [] for reading");
    1041             :                                         }
    1042       13901 :                                         opline->opcode += 6; /* 3+3 */
    1043       13901 :                                         break;
    1044             :                                 case BP_VAR_FUNC_ARG:
    1045         420 :                                         opline->opcode += 9; /* 3+3+3 */
    1046         420 :                                         opline->extended_value = arg_offset;
    1047         420 :                                         break;
    1048             :                                 case BP_VAR_UNSET:
    1049         355 :                                         if (opline->opcode == ZEND_FETCH_DIM_W && opline->op2.op_type == IS_UNUSED) {
    1050           1 :                                                 zend_error(E_COMPILE_ERROR, "Cannot use [] for unsetting");
    1051             :                                         }
    1052         354 :                                         opline->opcode += 12; /* 3+3+3+3 */
    1053             :                                         break;
    1054             :                         }
    1055      221092 :                         le = le->next;
    1056             :                 }
    1057      195608 :                 if (opline && type == BP_VAR_W && arg_offset) {
    1058         114 :                         opline->extended_value = ZEND_FETCH_MAKE_REF;
    1059             :                 }
    1060             :         }
    1061     1082530 :         zend_llist_destroy(fetch_list_ptr);
    1062     1082530 :         zend_stack_del_top(&CG(bp_stack));
    1063     1082530 : }
    1064             : /* }}} */
    1065             : 
    1066       26368 : void zend_do_add_string(znode *result, const znode *op1, znode *op2 TSRMLS_DC) /* {{{ */
    1067             : {
    1068             :         zend_op *opline;
    1069             : 
    1070       26368 :         if (Z_STRLEN(op2->u.constant) > 1) {
    1071       20661 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1072       20661 :                 opline->opcode = ZEND_ADD_STRING;
    1073        5707 :         } else if (Z_STRLEN(op2->u.constant) == 1) {
    1074        5701 :                 int ch = *Z_STRVAL(op2->u.constant);
    1075             : 
    1076             :                 /* Free memory and use ZEND_ADD_CHAR in case of 1 character strings */
    1077        5701 :                 efree(Z_STRVAL(op2->u.constant));
    1078        5701 :                 ZVAL_LONG(&op2->u.constant, ch);
    1079        5701 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1080        5701 :                 opline->opcode = ZEND_ADD_CHAR;
    1081             :         } else { /* String can be empty after a variable at the end of a heredoc */
    1082           6 :                 efree(Z_STRVAL(op2->u.constant));
    1083           6 :                 return;
    1084             :         }
    1085             : 
    1086       26362 :         if (op1) {
    1087       16503 :                 opline->op1 = *op1;
    1088       16503 :                 opline->result = *op1;
    1089             :         } else {
    1090        9859 :                 SET_UNUSED(opline->op1);
    1091        9859 :                 opline->result.op_type = IS_TMP_VAR;
    1092        9859 :                 opline->result.u.var = get_temporary_variable(CG(active_op_array));
    1093             :         }
    1094       26362 :         opline->op2 = *op2;
    1095       26362 :         *result = opline->result;
    1096             : }
    1097             : /* }}} */
    1098             : 
    1099       21450 : void zend_do_add_variable(znode *result, const znode *op1, const znode *op2 TSRMLS_DC) /* {{{ */
    1100             : {
    1101       21450 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1102             : 
    1103       21450 :         opline->opcode = ZEND_ADD_VAR;
    1104             : 
    1105       21450 :         if (op1) {
    1106       16957 :                 opline->op1 = *op1;
    1107       16957 :                 opline->result = *op1;
    1108             :         } else {
    1109        4493 :                 SET_UNUSED(opline->op1);
    1110        4493 :                 opline->result.op_type = IS_TMP_VAR;
    1111        4493 :                 opline->result.u.var = get_temporary_variable(CG(active_op_array));
    1112             :         }
    1113       21450 :         opline->op2 = *op2;
    1114       21450 :         *result = opline->result;
    1115       21450 : }
    1116             : /* }}} */
    1117             : 
    1118      322946 : void zend_do_free(znode *op1 TSRMLS_DC) /* {{{ */
    1119             : {
    1120      322946 :         if (op1->op_type==IS_TMP_VAR) {
    1121       10227 :                 zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1122             : 
    1123       10227 :                 opline->opcode = ZEND_FREE;
    1124       10227 :                 opline->op1 = *op1;
    1125       10227 :                 SET_UNUSED(opline->op2);
    1126      312719 :         } else if (op1->op_type==IS_VAR) {
    1127      298558 :                 zend_op *opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
    1128             : 
    1129      614653 :                 while (opline->opcode == ZEND_END_SILENCE || opline->opcode == ZEND_EXT_FCALL_END || opline->opcode == ZEND_OP_DATA) {
    1130       17537 :                         opline--;
    1131             :                 }
    1132      895474 :                 if (opline->result.op_type == IS_VAR
    1133      597116 :                         && opline->result.u.var == op1->u.var) {
    1134      298358 :                         opline->result.u.EA.type |= EXT_TYPE_UNUSED;
    1135             :                 } else {
    1136         823 :                         while (opline>CG(active_op_array)->opcodes) {
    1137         699 :                                 if (opline->opcode == ZEND_FETCH_DIM_R
    1138         623 :                                     && opline->op1.op_type == IS_VAR
    1139          76 :                                     && opline->op1.u.var == op1->u.var) {
    1140             :                                         /* This should the end of a list() construct
    1141             :                                          * Mark its result as unused
    1142             :                                          */
    1143          37 :                                         opline->extended_value = ZEND_FETCH_STANDARD;
    1144          37 :                                         break;
    1145        1003 :                                 } else if (opline->result.op_type==IS_VAR
    1146        1003 :                                         && opline->result.u.var == op1->u.var) {
    1147         163 :                                         if (opline->opcode == ZEND_NEW) {
    1148         163 :                                                 opline->result.u.EA.type |= EXT_TYPE_UNUSED;
    1149             :                                         }
    1150         163 :                                         break;
    1151             :                                 }
    1152         423 :                                 opline--;
    1153             :                         }
    1154             :                 }
    1155       14161 :         } else if (op1->op_type == IS_CONST) {
    1156       13889 :                 zval_dtor(&op1->u.constant);
    1157             :         }
    1158      322946 : }
    1159             : /* }}} */
    1160             : 
    1161         526 : int zend_do_verify_access_types(const znode *current_access_type, const znode *new_modifier) /* {{{ */
    1162             : {
    1163         806 :         if ((Z_LVAL(current_access_type->u.constant) & ZEND_ACC_PPP_MASK)
    1164         280 :                 && (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_PPP_MASK)) {
    1165           4 :                 zend_error(E_COMPILE_ERROR, "Multiple access type modifiers are not allowed");
    1166             :         }
    1167         544 :         if ((Z_LVAL(current_access_type->u.constant) & ZEND_ACC_ABSTRACT)
    1168          22 :                 && (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_ABSTRACT)) {
    1169           1 :                 zend_error(E_COMPILE_ERROR, "Multiple abstract modifiers are not allowed");
    1170             :         }
    1171         740 :         if ((Z_LVAL(current_access_type->u.constant) & ZEND_ACC_STATIC)
    1172         219 :                 && (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_STATIC)) {
    1173           1 :                 zend_error(E_COMPILE_ERROR, "Multiple static modifiers are not allowed");
    1174             :         }
    1175         528 :         if ((Z_LVAL(current_access_type->u.constant) & ZEND_ACC_FINAL)
    1176           8 :                 && (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_FINAL)) {
    1177           1 :                 zend_error(E_COMPILE_ERROR, "Multiple final modifiers are not allowed");
    1178             :         }
    1179         519 :         if (((Z_LVAL(current_access_type->u.constant) | Z_LVAL(new_modifier->u.constant)) & (ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL)) == (ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL)) {
    1180           4 :                 zend_error(E_COMPILE_ERROR, "Cannot use the final modifier on an abstract class member");
    1181             :         }
    1182         515 :         return (Z_LVAL(current_access_type->u.constant) | Z_LVAL(new_modifier->u.constant));
    1183             : }
    1184             : /* }}} */
    1185             : 
    1186       36229 : void zend_do_begin_function_declaration(znode *function_token, znode *function_name, int is_method, int return_reference, znode *fn_flags_znode TSRMLS_DC) /* {{{ */
    1187             : {
    1188             :         zend_op_array op_array;
    1189       36229 :         char *name = function_name->u.constant.value.str.val;
    1190       36229 :         int name_len = function_name->u.constant.value.str.len;
    1191       36229 :         int function_begin_line = function_token->u.opline_num;
    1192             :         zend_uint fn_flags;
    1193             :         char *lcname;
    1194             :         zend_bool orig_interactive;
    1195             :         ALLOCA_FLAG(use_heap)
    1196             : 
    1197       36229 :         if (is_method) {
    1198       16874 :                 if (CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE) {
    1199          81 :                         if ((Z_LVAL(fn_flags_znode->u.constant) & ~(ZEND_ACC_STATIC|ZEND_ACC_PUBLIC))) {
    1200           1 :                                 zend_error(E_COMPILE_ERROR, "Access type for interface method %s::%s() must be omitted", CG(active_class_entry)->name, function_name->u.constant.value.str.val);
    1201             :                         }
    1202          80 :                         Z_LVAL(fn_flags_znode->u.constant) |= ZEND_ACC_ABSTRACT; /* propagates to the rest of the parser */
    1203             :                 }
    1204       16873 :                 fn_flags = Z_LVAL(fn_flags_znode->u.constant); /* must be done *after* the above check */
    1205             :         } else {
    1206       19355 :                 fn_flags = 0;
    1207             :         }
    1208       36228 :         if ((fn_flags & ZEND_ACC_STATIC) && (fn_flags & ZEND_ACC_ABSTRACT) && !(CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE)) {
    1209           4 :                 zend_error(E_STRICT, "Static function %s%s%s() should not be abstract", is_method ? CG(active_class_entry)->name : "", is_method ? "::" : "", Z_STRVAL(function_name->u.constant));
    1210             :         }
    1211             : 
    1212       36228 :         function_token->u.op_array = CG(active_op_array);
    1213       36228 :         lcname = zend_str_tolower_dup(name, name_len);
    1214             : 
    1215       36228 :         orig_interactive = CG(interactive);
    1216       36228 :         CG(interactive) = 0;
    1217       36228 :         init_op_array(&op_array, ZEND_USER_FUNCTION, INITIAL_OP_ARRAY_SIZE TSRMLS_CC);
    1218       36228 :         CG(interactive) = orig_interactive;
    1219             : 
    1220       36228 :         op_array.function_name = name;
    1221       36228 :         op_array.return_reference = return_reference;
    1222       36228 :         op_array.fn_flags |= fn_flags;
    1223       36228 :         op_array.pass_rest_by_reference = 0;
    1224             : 
    1225       36228 :         op_array.scope = is_method?CG(active_class_entry):NULL;
    1226       36228 :         op_array.prototype = NULL;
    1227             : 
    1228       36228 :         op_array.line_start = zend_get_compiled_lineno(TSRMLS_C);
    1229             : 
    1230       36228 :         if (is_method) {
    1231       16873 :                 if (zend_hash_add(&CG(active_class_entry)->function_table, lcname, name_len+1, &op_array, sizeof(zend_op_array), (void **) &CG(active_op_array)) == FAILURE) {
    1232           1 :                         zend_error(E_COMPILE_ERROR, "Cannot redeclare %s::%s()", CG(active_class_entry)->name, name);
    1233             :                 }
    1234             : 
    1235       16872 :                 if (fn_flags & ZEND_ACC_ABSTRACT) {
    1236         121 :                         CG(active_class_entry)->ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
    1237             :                 }
    1238             : 
    1239       16872 :                 if (!(fn_flags & ZEND_ACC_PPP_MASK)) {
    1240           0 :                         fn_flags |= ZEND_ACC_PUBLIC;
    1241             :                 }
    1242             : 
    1243       16872 :                 if (CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE) {
    1244          81 :                         if ((name_len == sizeof(ZEND_CALL_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1))) {
    1245           1 :                                 if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
    1246           1 :                                         zend_error(E_WARNING, "The magic method __call() must have public visibility and cannot be static");
    1247             :                                 }
    1248          80 :                         } else if ((name_len == sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1))) {
    1249           1 :                                 if ((fn_flags & (ZEND_ACC_PPP_MASK ^ ZEND_ACC_PUBLIC)) || (fn_flags & ZEND_ACC_STATIC) == 0) {
    1250           1 :                                         zend_error(E_WARNING, "The magic method __callStatic() must have public visibility and be static");
    1251             :                                 }
    1252          78 :                         } else if ((name_len == sizeof(ZEND_GET_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME)-1))) {
    1253           0 :                                 if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
    1254           0 :                                         zend_error(E_WARNING, "The magic method __get() must have public visibility and cannot be static");
    1255             :                                 }
    1256          78 :                         } else if ((name_len == sizeof(ZEND_SET_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME)-1))) {
    1257           0 :                                 if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
    1258           0 :                                         zend_error(E_WARNING, "The magic method __set() must have public visibility and cannot be static");
    1259             :                                 }
    1260          78 :                         } else if ((name_len == sizeof(ZEND_UNSET_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_UNSET_FUNC_NAME, sizeof(ZEND_UNSET_FUNC_NAME)-1))) {
    1261           0 :                                 if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
    1262           0 :                                         zend_error(E_WARNING, "The magic method __unset() must have public visibility and cannot be static");
    1263             :                                 }
    1264          78 :                         } else if ((name_len == sizeof(ZEND_ISSET_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME)-1))) {
    1265           0 :                                 if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
    1266           0 :                                         zend_error(E_WARNING, "The magic method __isset() must have public visibility and cannot be static");
    1267             :                                 }
    1268          78 :                         } else if ((name_len == sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME)-1))) {
    1269           0 :                                 if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
    1270           0 :                                         zend_error(E_WARNING, "The magic method __toString() must have public visibility and cannot be static");
    1271             :                                 }
    1272             :                         }
    1273             :                 } else {
    1274             :                         char *class_lcname;
    1275             :                         
    1276       16792 :                         class_lcname = do_alloca(CG(active_class_entry)->name_length + 1, use_heap);
    1277       16792 :                         zend_str_tolower_copy(class_lcname, CG(active_class_entry)->name, CG(active_class_entry)->name_length);
    1278             :                         /* Improve after RC: cache the lowercase class name */
    1279             : 
    1280       17028 :                         if ((CG(active_class_entry)->name_length == name_len) && (!memcmp(class_lcname, lcname, name_len))) {
    1281         236 :                                 if (!CG(active_class_entry)->constructor) {
    1282         227 :                                         CG(active_class_entry)->constructor = (zend_function *) CG(active_op_array);
    1283             :                                 }
    1284       18104 :                         } else if ((name_len == sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)))) {
    1285        1548 :                                 if (CG(active_class_entry)->constructor) {
    1286           6 :                                         zend_error(E_STRICT, "Redefining already defined constructor for class %s", CG(active_class_entry)->name);
    1287             :                                 }
    1288        1548 :                                 CG(active_class_entry)->constructor = (zend_function *) CG(active_op_array);
    1289       15154 :                         } else if ((name_len == sizeof(ZEND_DESTRUCTOR_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_DESTRUCTOR_FUNC_NAME, sizeof(ZEND_DESTRUCTOR_FUNC_NAME)-1))) {
    1290         146 :                                 CG(active_class_entry)->destructor = (zend_function *) CG(active_op_array);
    1291       14882 :                         } else if ((name_len == sizeof(ZEND_CLONE_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME)-1))) {
    1292          20 :                                 CG(active_class_entry)->clone = (zend_function *) CG(active_op_array);
    1293       14899 :                         } else if ((name_len == sizeof(ZEND_CALL_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1))) {
    1294          57 :                                 if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
    1295           2 :                                         zend_error(E_WARNING, "The magic method __call() must have public visibility and cannot be static");
    1296             :                                 }
    1297          57 :                                 CG(active_class_entry)->__call = (zend_function *) CG(active_op_array);
    1298       14805 :                         } else if ((name_len == sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1))) {
    1299          20 :                                 if ((fn_flags & (ZEND_ACC_PPP_MASK ^ ZEND_ACC_PUBLIC)) || (fn_flags & ZEND_ACC_STATIC) == 0) {
    1300           1 :                                         zend_error(E_WARNING, "The magic method __callStatic() must have public visibility and be static");
    1301             :                                 }
    1302          20 :                                 CG(active_class_entry)->__callstatic = (zend_function *) CG(active_op_array);
    1303       14822 :                         } else if ((name_len == sizeof(ZEND_GET_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME)-1))) {
    1304          57 :                                 if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
    1305           0 :                                         zend_error(E_WARNING, "The magic method __get() must have public visibility and cannot be static");
    1306             :                                 }
    1307          57 :                                 CG(active_class_entry)->__get = (zend_function *) CG(active_op_array);
    1308       14766 :                         } else if ((name_len == sizeof(ZEND_SET_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME)-1))) {
    1309          58 :                                 if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
    1310           2 :                                         zend_error(E_WARNING, "The magic method __set() must have public visibility and cannot be static");
    1311             :                                 }
    1312          58 :                                 CG(active_class_entry)->__set = (zend_function *) CG(active_op_array);
    1313       14667 :                         } else if ((name_len == sizeof(ZEND_UNSET_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_UNSET_FUNC_NAME, sizeof(ZEND_UNSET_FUNC_NAME)-1))) {
    1314          17 :                                 if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
    1315           3 :                                         zend_error(E_WARNING, "The magic method __unset() must have public visibility and cannot be static");
    1316             :                                 }
    1317          17 :                                 CG(active_class_entry)->__unset = (zend_function *) CG(active_op_array);
    1318       14647 :                         } else if ((name_len == sizeof(ZEND_ISSET_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME)-1))) {
    1319          14 :                                 if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
    1320           0 :                                         zend_error(E_WARNING, "The magic method __isset() must have public visibility and cannot be static");
    1321             :                                 }
    1322          14 :                                 CG(active_class_entry)->__isset = (zend_function *) CG(active_op_array);
    1323       15325 :                         } else if ((name_len == sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME)-1))) {
    1324         706 :                                 if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
    1325           1 :                                         zend_error(E_WARNING, "The magic method __toString() must have public visibility and cannot be static");
    1326             :                                 }                               
    1327         706 :                                 CG(active_class_entry)->__tostring = (zend_function *) CG(active_op_array);
    1328       13913 :                         } else if (!(fn_flags & ZEND_ACC_STATIC)) {
    1329        6752 :                                 CG(active_op_array)->fn_flags |= ZEND_ACC_ALLOW_STATIC;
    1330             :                         }
    1331       16792 :                         free_alloca(class_lcname, use_heap);
    1332             :                 }
    1333             : 
    1334       16872 :                 efree(lcname);
    1335             :         } else {
    1336       19355 :                 zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1337             : 
    1338       19355 :                 if (CG(current_namespace)) {
    1339             :                         /* Prefix function name with current namespace name */
    1340             :                         znode tmp;
    1341             : 
    1342          72 :                         tmp.u.constant = *CG(current_namespace);
    1343          72 :                         zval_copy_ctor(&tmp.u.constant);
    1344          72 :                         zend_do_build_namespace_name(&tmp, &tmp, function_name TSRMLS_CC);
    1345          72 :                         op_array.function_name = Z_STRVAL(tmp.u.constant);
    1346          72 :                         efree(lcname);
    1347          72 :                         name_len = Z_STRLEN(tmp.u.constant);
    1348          72 :                         lcname = zend_str_tolower_dup(Z_STRVAL(tmp.u.constant), name_len);
    1349             :                 }
    1350             : 
    1351       19355 :                 opline->opcode = ZEND_DECLARE_FUNCTION;
    1352       19355 :                 opline->op1.op_type = IS_CONST;
    1353       19355 :                 build_runtime_defined_function_key(&opline->op1.u.constant, lcname, name_len TSRMLS_CC);
    1354       19355 :                 opline->op2.op_type = IS_CONST;
    1355       19355 :                 opline->op2.u.constant.type = IS_STRING;
    1356       19355 :                 opline->op2.u.constant.value.str.val = lcname;
    1357       19355 :                 opline->op2.u.constant.value.str.len = name_len;
    1358       19355 :                 Z_SET_REFCOUNT(opline->op2.u.constant, 1);
    1359       19355 :                 opline->extended_value = ZEND_DECLARE_FUNCTION;
    1360       19355 :                 zend_hash_update(CG(function_table), opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len, &op_array, sizeof(zend_op_array), (void **) &CG(active_op_array));
    1361             :         }
    1362             : 
    1363       36227 :         if (CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO) {
    1364           0 :                 zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1365             : 
    1366           0 :                 opline->opcode = ZEND_EXT_NOP;
    1367           0 :                 opline->lineno = function_begin_line;
    1368           0 :                 SET_UNUSED(opline->op1);
    1369           0 :                 SET_UNUSED(opline->op2);
    1370             :         }
    1371             : 
    1372             :         {
    1373             :                 /* Push a seperator to the switch and foreach stacks */
    1374             :                 zend_switch_entry switch_entry;
    1375             : 
    1376       36227 :                 switch_entry.cond.op_type = IS_UNUSED;
    1377       36227 :                 switch_entry.default_case = 0;
    1378       36227 :                 switch_entry.control_var = 0;
    1379             : 
    1380       36227 :                 zend_stack_push(&CG(switch_cond_stack), (void *) &switch_entry, sizeof(switch_entry));
    1381             : 
    1382             :                 {
    1383             :                         /* Foreach stack separator */
    1384             :                         zend_op dummy_opline;
    1385             : 
    1386       36227 :                         dummy_opline.result.op_type = IS_UNUSED;
    1387       36227 :                         dummy_opline.op1.op_type = IS_UNUSED;
    1388             : 
    1389       36227 :                         zend_stack_push(&CG(foreach_copy_stack), (void *) &dummy_opline, sizeof(zend_op));
    1390             :                 }
    1391             :         }
    1392             : 
    1393       36227 :         if (CG(doc_comment)) {
    1394        2319 :                 CG(active_op_array)->doc_comment = CG(doc_comment);
    1395        2319 :                 CG(active_op_array)->doc_comment_len = CG(doc_comment_len);
    1396        2319 :                 CG(doc_comment) = NULL;
    1397        2319 :                 CG(doc_comment_len) = 0;
    1398             :         }
    1399             : 
    1400       36227 :         zend_stack_push(&CG(labels_stack), (void *) &CG(labels), sizeof(HashTable*));
    1401       36227 :         CG(labels) = NULL;
    1402       36227 : }
    1403             : /* }}} */
    1404             : 
    1405         157 : void zend_do_begin_lambda_function_declaration(znode *result, znode *function_token, int return_reference TSRMLS_DC) /* {{{ */
    1406             : {
    1407             :         znode          function_name;
    1408         157 :         zend_op_array *current_op_array = CG(active_op_array);
    1409         157 :         int            current_op_number = get_next_op_number(CG(active_op_array));
    1410             :         zend_op       *current_op;
    1411             : 
    1412         157 :         function_name.op_type = IS_CONST;
    1413         157 :         ZVAL_STRINGL(&function_name.u.constant, "{closure}", sizeof("{closure}")-1, 1);
    1414             : 
    1415         157 :         zend_do_begin_function_declaration(function_token, &function_name, 0, return_reference, NULL TSRMLS_CC);
    1416             : 
    1417         157 :         result->op_type = IS_TMP_VAR;
    1418         157 :         result->u.var = get_temporary_variable(current_op_array);
    1419             : 
    1420         157 :         current_op = &current_op_array->opcodes[current_op_number];
    1421         157 :         current_op->opcode = ZEND_DECLARE_LAMBDA_FUNCTION;
    1422         157 :         zval_dtor(&current_op->op2.u.constant);
    1423         157 :         ZVAL_LONG(&current_op->op2.u.constant, zend_hash_func(Z_STRVAL(current_op->op1.u.constant), Z_STRLEN(current_op->op1.u.constant)));
    1424         157 :         current_op->result = *result;
    1425         157 :         CG(active_op_array)->fn_flags |= ZEND_ACC_CLOSURE;
    1426         157 : }
    1427             : /* }}} */
    1428             : 
    1429           0 : void zend_do_handle_exception(TSRMLS_D) /* {{{ */
    1430             : {
    1431           0 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1432             : 
    1433           0 :         opline->opcode = ZEND_HANDLE_EXCEPTION;
    1434           0 :         SET_UNUSED(opline->op1);
    1435           0 :         SET_UNUSED(opline->op2);
    1436           0 : }
    1437             : /* }}} */
    1438             : 
    1439       36212 : void zend_do_end_function_declaration(const znode *function_token TSRMLS_DC) /* {{{ */
    1440             : {
    1441             :         char lcname[16];
    1442             :         int name_len;
    1443             : 
    1444       36212 :         zend_do_extended_info(TSRMLS_C);
    1445       36212 :         zend_do_return(NULL, 0 TSRMLS_CC);
    1446             : 
    1447       36212 :         pass_two(CG(active_op_array) TSRMLS_CC);
    1448       36212 :         zend_release_labels(TSRMLS_C);
    1449             : 
    1450       36212 :         if (CG(active_class_entry)) {
    1451       16887 :                 zend_check_magic_method_implementation(CG(active_class_entry), (zend_function*)CG(active_op_array), E_COMPILE_ERROR TSRMLS_CC);
    1452             :         } else {
    1453             :                 /* we don't care if the function name is longer, in fact lowercasing only 
    1454             :                  * the beginning of the name speeds up the check process */
    1455       19325 :                 name_len = strlen(CG(active_op_array)->function_name);
    1456       19325 :                 zend_str_tolower_copy(lcname, CG(active_op_array)->function_name, MIN(name_len, sizeof(lcname)-1));
    1457       19325 :                 lcname[sizeof(lcname)-1] = '\0'; /* zend_str_tolower_copy won't necessarily set the zero byte */
    1458       19325 :                 if (name_len == sizeof(ZEND_AUTOLOAD_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME)) && CG(active_op_array)->num_args != 1) {
    1459           1 :                         zend_error(E_COMPILE_ERROR, "%s() must take exactly 1 argument", ZEND_AUTOLOAD_FUNC_NAME);
    1460             :                 }               
    1461             :         }
    1462             : 
    1463       36195 :         CG(active_op_array)->line_end = zend_get_compiled_lineno(TSRMLS_C);
    1464       36195 :         CG(active_op_array) = function_token->u.op_array;
    1465             : 
    1466             : 
    1467             :         /* Pop the switch and foreach seperators */
    1468       36195 :         zend_stack_del_top(&CG(switch_cond_stack));
    1469       36195 :         zend_stack_del_top(&CG(foreach_copy_stack));
    1470       36195 : }
    1471             : /* }}} */
    1472             : 
    1473      134776 : void zend_do_receive_arg(zend_uchar op, const znode *var, const znode *offset, const znode *initialization, znode *class_type, const znode *varname, zend_uchar pass_by_reference TSRMLS_DC) /* {{{ */
    1474             : {
    1475             :         zend_op *opline;
    1476             :         zend_arg_info *cur_arg_info;
    1477             : 
    1478      135243 :         if (class_type->op_type == IS_CONST &&
    1479         326 :             Z_TYPE(class_type->u.constant) == IS_STRING &&
    1480         141 :             Z_STRLEN(class_type->u.constant) == 0) {
    1481             :                 /* Usage of namespace as class name not in namespace */
    1482           0 :                 zval_dtor(&class_type->u.constant);
    1483           0 :                 zend_error(E_COMPILE_ERROR, "Cannot use 'namespace' as a class name");
    1484           0 :                 return;
    1485             :         }
    1486             : 
    1487      269550 :         if (var->op_type == IS_CV &&
    1488      134774 :             var->u.var == CG(active_op_array)->this_var &&
    1489           0 :             (CG(active_op_array)->fn_flags & ZEND_ACC_STATIC) == 0) {
    1490           0 :                 zend_error(E_COMPILE_ERROR, "Cannot re-assign $this");
    1491      134783 :         } else if (var->op_type == IS_VAR &&
    1492           2 :             CG(active_op_array)->scope &&
    1493           2 :                 ((CG(active_op_array)->fn_flags & ZEND_ACC_STATIC) == 0) &&
    1494           1 :                 (Z_TYPE(varname->u.constant) == IS_STRING) &&
    1495           1 :                 (Z_STRLEN(varname->u.constant) == sizeof("this")-1) &&
    1496           1 :                 (memcmp(Z_STRVAL(varname->u.constant), "this", sizeof("this")) == 0)) {
    1497           1 :                 zend_error(E_COMPILE_ERROR, "Cannot re-assign $this");
    1498             :         }
    1499             : 
    1500      134775 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1501      134775 :         CG(active_op_array)->num_args++;
    1502      134775 :         opline->opcode = op;
    1503      134775 :         opline->result = *var;
    1504      134775 :         opline->op1 = *offset;
    1505      134775 :         if (op == ZEND_RECV_INIT) {
    1506       14708 :                 opline->op2 = *initialization;
    1507             :         } else {
    1508      120067 :                 CG(active_op_array)->required_num_args = CG(active_op_array)->num_args;
    1509      120067 :                 SET_UNUSED(opline->op2);
    1510             :         }
    1511      134775 :         CG(active_op_array)->arg_info = erealloc(CG(active_op_array)->arg_info, sizeof(zend_arg_info)*(CG(active_op_array)->num_args));
    1512      134775 :         cur_arg_info = &CG(active_op_array)->arg_info[CG(active_op_array)->num_args-1];
    1513      134775 :         cur_arg_info->name = estrndup(varname->u.constant.value.str.val, varname->u.constant.value.str.len);
    1514      134775 :         cur_arg_info->name_len = varname->u.constant.value.str.len;
    1515      134775 :         cur_arg_info->array_type_hint = 0;
    1516      134775 :         cur_arg_info->allow_null = 1;
    1517      134775 :         cur_arg_info->pass_by_reference = pass_by_reference;
    1518      134775 :         cur_arg_info->class_name = NULL;
    1519      134775 :         cur_arg_info->class_name_len = 0;
    1520             : 
    1521      134775 :         if (class_type->op_type != IS_UNUSED) {
    1522         326 :                 cur_arg_info->allow_null = 0;
    1523         326 :                 if (class_type->u.constant.type == IS_STRING) {
    1524         141 :                         if (ZEND_FETCH_CLASS_DEFAULT == zend_get_class_fetch_type(Z_STRVAL(class_type->u.constant), Z_STRLEN(class_type->u.constant))) {
    1525         137 :                                 zend_resolve_class_name(class_type, &opline->extended_value, 1 TSRMLS_CC);
    1526             :                         }
    1527         140 :                         cur_arg_info->class_name = class_type->u.constant.value.str.val;
    1528         140 :                         cur_arg_info->class_name_len = class_type->u.constant.value.str.len;
    1529         140 :                         if (op == ZEND_RECV_INIT) {
    1530          29 :                                 if (Z_TYPE(initialization->u.constant) == IS_NULL || (Z_TYPE(initialization->u.constant) == IS_CONSTANT && !strcasecmp(Z_STRVAL(initialization->u.constant), "NULL"))) {
    1531          14 :                                         cur_arg_info->allow_null = 1;
    1532             :                                 } else {
    1533           1 :                                         zend_error(E_COMPILE_ERROR, "Default value for parameters with a class type hint can only be NULL");
    1534             :                                 }
    1535             :                         }
    1536             :                 } else {
    1537         185 :                         cur_arg_info->array_type_hint = 1;
    1538         185 :                         cur_arg_info->class_name = NULL;
    1539         185 :                         cur_arg_info->class_name_len = 0;
    1540         185 :                         if (op == ZEND_RECV_INIT) {
    1541          11 :                                 if (Z_TYPE(initialization->u.constant) == IS_NULL || (Z_TYPE(initialization->u.constant) == IS_CONSTANT && !strcasecmp(Z_STRVAL(initialization->u.constant), "NULL"))) {
    1542           3 :                                         cur_arg_info->allow_null = 1;
    1543           5 :                                 } else if (Z_TYPE(initialization->u.constant) != IS_ARRAY && Z_TYPE(initialization->u.constant) != IS_CONSTANT_ARRAY) {
    1544           1 :                                         zend_error(E_COMPILE_ERROR, "Default value for parameters with array type hint can only be an array or NULL");
    1545             :                                 }
    1546             :                         }
    1547             :                 }
    1548             :         }
    1549      134772 :         opline->result.u.EA.type |= EXT_TYPE_UNUSED;
    1550             : }
    1551             : /* }}} */
    1552             : 
    1553      310175 : int zend_do_begin_function_call(znode *function_name, zend_bool check_namespace TSRMLS_DC) /* {{{ */
    1554             : {
    1555             :         zend_function *function;
    1556             :         char *lcname;
    1557      310175 :         char *is_compound = memchr(Z_STRVAL(function_name->u.constant), '\\', Z_STRLEN(function_name->u.constant));
    1558             : 
    1559      310175 :         zend_resolve_non_class_name(function_name, check_namespace TSRMLS_CC);
    1560             : 
    1561      310175 :         if (check_namespace && CG(current_namespace) && !is_compound) {
    1562             :                         /* We assume we call function from the current namespace
    1563             :                         if it is not prefixed. */
    1564             : 
    1565             :                         /* In run-time PHP will check for function with full name and
    1566             :                         internal function with short name */
    1567         280 :                         zend_do_begin_dynamic_function_call(function_name, 1 TSRMLS_CC);
    1568         280 :                         return 1;
    1569             :         } 
    1570             : 
    1571      309895 :         lcname = zend_str_tolower_dup(function_name->u.constant.value.str.val, function_name->u.constant.value.str.len);
    1572      615471 :         if ((zend_hash_find(CG(function_table), lcname, function_name->u.constant.value.str.len+1, (void **) &function)==FAILURE) ||
    1573      305576 :                 ((CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS) &&
    1574           0 :                 (function->type == ZEND_INTERNAL_FUNCTION))) {
    1575        4319 :                         zend_do_begin_dynamic_function_call(function_name, 0 TSRMLS_CC);
    1576        4319 :                         efree(lcname);
    1577        4319 :                         return 1; /* Dynamic */
    1578             :         } 
    1579      305576 :         efree(function_name->u.constant.value.str.val);
    1580      305576 :         function_name->u.constant.value.str.val = lcname;
    1581             :         
    1582      305576 :         zend_stack_push(&CG(function_call_stack), (void *) &function, sizeof(zend_function *));
    1583      305576 :         zend_do_extended_fcall_begin(TSRMLS_C);
    1584      305576 :         return 0;
    1585             : }
    1586             : /* }}} */
    1587             : 
    1588       34845 : void zend_do_begin_method_call(znode *left_bracket TSRMLS_DC) /* {{{ */
    1589             : {
    1590             :         zend_op *last_op;
    1591             :         int last_op_number;
    1592       34845 :         unsigned char *ptr = NULL;
    1593             : 
    1594       34845 :         zend_do_end_variable_parse(left_bracket, BP_VAR_R, 0 TSRMLS_CC);
    1595       34845 :         zend_do_begin_variable_parse(TSRMLS_C);
    1596             : 
    1597       34845 :         last_op_number = get_next_op_number(CG(active_op_array))-1;
    1598       34845 :         last_op = &CG(active_op_array)->opcodes[last_op_number];
    1599             : 
    1600       37572 :         if ((last_op->op2.op_type == IS_CONST) && (last_op->op2.u.constant.type == IS_STRING) && (last_op->op2.u.constant.value.str.len == sizeof(ZEND_CLONE_FUNC_NAME)-1)
    1601        2727 :                 && !zend_binary_strcasecmp(last_op->op2.u.constant.value.str.val, last_op->op2.u.constant.value.str.len, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME)-1)) {
    1602           1 :                 zend_error(E_COMPILE_ERROR, "Cannot call __clone() method on objects - use 'clone $obj' instead");
    1603             :         }
    1604             : 
    1605       34844 :         if (last_op->opcode == ZEND_FETCH_OBJ_R) {
    1606       34839 :                 last_op->opcode = ZEND_INIT_METHOD_CALL;
    1607       34839 :                 SET_UNUSED(last_op->result);
    1608       34839 :                 Z_LVAL(left_bracket->u.constant) = ZEND_INIT_FCALL_BY_NAME;
    1609             :         } else {
    1610           5 :                 zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1611           5 :                 opline->opcode = ZEND_INIT_FCALL_BY_NAME;
    1612           5 :                 opline->op2 = *left_bracket;
    1613           5 :                 if (opline->op2.op_type == IS_CONST) {
    1614           0 :                         opline->op1.op_type = IS_CONST;
    1615           0 :                         Z_TYPE(opline->op1.u.constant) = IS_STRING;
    1616           0 :                         Z_STRVAL(opline->op1.u.constant) = zend_str_tolower_dup(Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant));
    1617           0 :                         Z_STRLEN(opline->op1.u.constant) = Z_STRLEN(opline->op2.u.constant);
    1618           0 :                         opline->extended_value = zend_hash_func(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant) + 1);
    1619             :                 } else {
    1620           5 :                         opline->extended_value = 0;
    1621           5 :                         SET_UNUSED(opline->op1);
    1622             :                 }
    1623             :         }
    1624             : 
    1625       34844 :         zend_stack_push(&CG(function_call_stack), (void *) &ptr, sizeof(zend_function *));
    1626       34844 :         zend_do_extended_fcall_begin(TSRMLS_C);
    1627       34844 : }
    1628             : /* }}} */
    1629             : 
    1630          89 : void zend_do_clone(znode *result, const znode *expr TSRMLS_DC) /* {{{ */
    1631             : {
    1632          89 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1633             : 
    1634          89 :         opline->opcode = ZEND_CLONE;
    1635          89 :         opline->op1 = *expr;
    1636          89 :         SET_UNUSED(opline->op2);
    1637          89 :         opline->result.op_type = IS_VAR;
    1638          89 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    1639          89 :         *result = opline->result;
    1640          89 : }
    1641             : /* }}} */
    1642             : 
    1643        6487 : void zend_do_begin_dynamic_function_call(znode *function_name, int ns_call TSRMLS_DC) /* {{{ */
    1644             : {
    1645        6487 :         unsigned char *ptr = NULL;
    1646             :         zend_op *opline, *opline2;
    1647             : 
    1648        6487 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1649        6487 :         if (ns_call) {
    1650             :                 char *slash;
    1651             :                 int prefix_len, name_len;
    1652             :                 /* In run-time PHP will check for function with full name and
    1653             :                    internal function with short name */
    1654         280 :                 opline->opcode = ZEND_INIT_NS_FCALL_BY_NAME;
    1655         280 :                 opline->op2 = *function_name;
    1656         280 :                 opline->extended_value = 0;
    1657         280 :                 opline->op1.op_type = IS_CONST;
    1658         280 :                 Z_TYPE(opline->op1.u.constant) = IS_STRING;
    1659         280 :                 Z_STRVAL(opline->op1.u.constant) = zend_str_tolower_dup(Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant));
    1660         280 :                 Z_STRLEN(opline->op1.u.constant) = Z_STRLEN(opline->op2.u.constant);
    1661         280 :                 opline->extended_value = zend_hash_func(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant) + 1);
    1662         280 :                 slash = zend_memrchr(Z_STRVAL(opline->op1.u.constant), '\\', Z_STRLEN(opline->op1.u.constant));
    1663         280 :                 prefix_len = slash-Z_STRVAL(opline->op1.u.constant)+1;
    1664         280 :                 name_len = Z_STRLEN(opline->op1.u.constant)-prefix_len;
    1665         280 :                 opline2 = get_next_op(CG(active_op_array) TSRMLS_CC);
    1666         280 :                 opline2->opcode = ZEND_OP_DATA;
    1667         280 :                 opline2->op1.op_type = IS_CONST;
    1668         280 :                 Z_TYPE(opline2->op1.u.constant) = IS_LONG;
    1669         280 :                 if(!slash) {
    1670           0 :                         zend_error(E_CORE_ERROR, "Namespaced name %s should contain slash", Z_STRVAL(opline->op1.u.constant));
    1671             :                 }
    1672             :                 /* this is the length of namespace prefix */
    1673         280 :                 Z_LVAL(opline2->op1.u.constant) = prefix_len;
    1674             :                 /* this is the hash of the non-prefixed part, lowercased */
    1675         280 :                 opline2->extended_value = zend_hash_func(slash+1, name_len+1);
    1676         280 :                 SET_UNUSED(opline2->op2);
    1677             :         } else {
    1678        6207 :                 opline->opcode = ZEND_INIT_FCALL_BY_NAME;
    1679        6207 :                 opline->op2 = *function_name;
    1680        6207 :                 if (opline->op2.op_type == IS_CONST) {
    1681        4319 :                         opline->op1.op_type = IS_CONST;
    1682        4319 :                         Z_TYPE(opline->op1.u.constant) = IS_STRING;
    1683        4319 :                         Z_STRVAL(opline->op1.u.constant) = zend_str_tolower_dup(Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant));
    1684        4319 :                         Z_STRLEN(opline->op1.u.constant) = Z_STRLEN(opline->op2.u.constant);
    1685        4319 :                         opline->extended_value = zend_hash_func(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant) + 1);
    1686             :                 } else {
    1687        1888 :                         opline->extended_value = 0;
    1688        1888 :                         SET_UNUSED(opline->op1);
    1689             :                 }
    1690             :         }
    1691             : 
    1692        6487 :         zend_stack_push(&CG(function_call_stack), (void *) &ptr, sizeof(zend_function *));
    1693        6487 :         zend_do_extended_fcall_begin(TSRMLS_C);
    1694        6487 : }
    1695             : /* }}} */
    1696             : 
    1697      391369 : void zend_resolve_non_class_name(znode *element_name, zend_bool check_namespace TSRMLS_DC) /* {{{ */
    1698             : {
    1699             :         znode tmp;
    1700             :         int len;
    1701             :         zval **ns;
    1702      391369 :         char *lcname, *compound = memchr(Z_STRVAL(element_name->u.constant), '\\', Z_STRLEN(element_name->u.constant));
    1703             : 
    1704      391369 :         if (Z_STRVAL(element_name->u.constant)[0] == '\\') {
    1705             :                 /* name starts with \ so it is known and unambiguos, nothing to do here but shorten it */
    1706          58 :                 memmove(Z_STRVAL(element_name->u.constant), Z_STRVAL(element_name->u.constant)+1, Z_STRLEN(element_name->u.constant));
    1707          58 :                 --Z_STRLEN(element_name->u.constant);
    1708          58 :                 return;
    1709             :         }
    1710             : 
    1711      391311 :         if(!check_namespace) {
    1712          14 :                 return;
    1713             :         }
    1714             : 
    1715      391297 :         if (compound && CG(current_import)) {
    1716          27 :                 len = compound - Z_STRVAL(element_name->u.constant);
    1717          27 :                 lcname = zend_str_tolower_dup(Z_STRVAL(element_name->u.constant), len);
    1718             :                 /* Check if first part of compound name is an import name */
    1719          27 :                 if (zend_hash_find(CG(current_import), lcname, len+1, (void**)&ns) == SUCCESS) {
    1720             :                         /* Substitute import name */
    1721          12 :                         tmp.op_type = IS_CONST;
    1722          12 :                         tmp.u.constant = **ns;
    1723          12 :                         zval_copy_ctor(&tmp.u.constant);
    1724          12 :                         len += 1;
    1725          12 :                         Z_STRLEN(element_name->u.constant) -= len;
    1726          12 :                         memmove(Z_STRVAL(element_name->u.constant), Z_STRVAL(element_name->u.constant)+len, Z_STRLEN(element_name->u.constant)+1);
    1727          12 :                         zend_do_build_namespace_name(&tmp, &tmp, element_name TSRMLS_CC);
    1728          12 :                         *element_name = tmp;
    1729          12 :                         efree(lcname);
    1730          12 :                         return;
    1731             :                 }
    1732          15 :                 efree(lcname);
    1733             :         }
    1734             : 
    1735      391285 :         if (CG(current_namespace)) {
    1736         375 :                 tmp = *element_name;
    1737         375 :                 Z_STRLEN(tmp.u.constant) = sizeof("\\")-1 + Z_STRLEN(element_name->u.constant) + Z_STRLEN_P(CG(current_namespace));
    1738         375 :                 Z_STRVAL(tmp.u.constant) = (char *) emalloc(Z_STRLEN(tmp.u.constant)+1);
    1739         375 :                 memcpy(Z_STRVAL(tmp.u.constant), Z_STRVAL_P(CG(current_namespace)), Z_STRLEN_P(CG(current_namespace)));
    1740         375 :                 memcpy(&(Z_STRVAL(tmp.u.constant)[Z_STRLEN_P(CG(current_namespace))]), "\\", sizeof("\\")-1);
    1741         375 :                 memcpy(&(Z_STRVAL(tmp.u.constant)[Z_STRLEN_P(CG(current_namespace)) + sizeof("\\")-1]), Z_STRVAL(element_name->u.constant), Z_STRLEN(element_name->u.constant)+1);
    1742         375 :                 STR_FREE(Z_STRVAL(element_name->u.constant));
    1743         375 :                 *element_name = tmp;
    1744             :         }
    1745             : }
    1746             : /* }}} */
    1747             : 
    1748       32578 : void zend_resolve_class_name(znode *class_name, ulong *fetch_type, int check_ns_name TSRMLS_DC) /* {{{ */
    1749             : {
    1750             :         char *compound;
    1751             :         char *lcname;
    1752             :         zval **ns;
    1753             :         znode tmp;
    1754             :         int len;
    1755             : 
    1756       32578 :         compound = memchr(Z_STRVAL(class_name->u.constant), '\\', Z_STRLEN(class_name->u.constant));
    1757       32578 :         if (compound) {
    1758             :                 /* This is a compound class name that contains namespace prefix */
    1759         168 :                 if (Z_STRVAL(class_name->u.constant)[0] == '\\') {
    1760             :                     /* The STRING name has "\" prefix */
    1761         140 :                     Z_STRLEN(class_name->u.constant) -= 1;
    1762         140 :                     memmove(Z_STRVAL(class_name->u.constant), Z_STRVAL(class_name->u.constant)+1, Z_STRLEN(class_name->u.constant)+1);
    1763         140 :                         Z_STRVAL(class_name->u.constant) = erealloc(
    1764             :                                 Z_STRVAL(class_name->u.constant),
    1765             :                                 Z_STRLEN(class_name->u.constant) + 1);
    1766             : 
    1767         140 :                         if (ZEND_FETCH_CLASS_DEFAULT != zend_get_class_fetch_type(Z_STRVAL(class_name->u.constant), Z_STRLEN(class_name->u.constant))) {
    1768           1 :                                 zend_error(E_COMPILE_ERROR, "'\\%s' is an invalid class name", Z_STRVAL(class_name->u.constant));
    1769             :                         }
    1770             :                 } else { 
    1771          28 :                         if (CG(current_import)) {
    1772          21 :                                 len = compound - Z_STRVAL(class_name->u.constant);
    1773          21 :                                 lcname = zend_str_tolower_dup(Z_STRVAL(class_name->u.constant), len);
    1774             :                                 /* Check if first part of compound name is an import name */
    1775          21 :                                 if (zend_hash_find(CG(current_import), lcname, len+1, (void**)&ns) == SUCCESS) {
    1776             :                                         /* Substitute import name */
    1777          14 :                                         tmp.op_type = IS_CONST;
    1778          14 :                                         tmp.u.constant = **ns;
    1779          14 :                                         zval_copy_ctor(&tmp.u.constant);
    1780          14 :                                         len += 1;
    1781          14 :                                         Z_STRLEN(class_name->u.constant) -= len;
    1782          14 :                                         memmove(Z_STRVAL(class_name->u.constant), Z_STRVAL(class_name->u.constant)+len, Z_STRLEN(class_name->u.constant)+1);
    1783          14 :                                         zend_do_build_namespace_name(&tmp, &tmp, class_name TSRMLS_CC);
    1784          14 :                                         *class_name = tmp;
    1785          14 :                                         efree(lcname);
    1786          14 :                                         return;
    1787             :                                 }
    1788           7 :                                 efree(lcname);
    1789             :                         }
    1790             :                         /* Here name is not prefixed with \ and not imported */
    1791          14 :                         if (CG(current_namespace)) {
    1792          10 :                                 tmp.op_type = IS_CONST;
    1793          10 :                                 tmp.u.constant = *CG(current_namespace);
    1794          10 :                                 zval_copy_ctor(&tmp.u.constant);
    1795          10 :                                 zend_do_build_namespace_name(&tmp, &tmp, class_name TSRMLS_CC);
    1796          10 :                                 *class_name = tmp;
    1797             :                         }
    1798             :                 }
    1799       32410 :         } else if (CG(current_import) || CG(current_namespace)) {
    1800             :                 /* this is a plain name (without \) */
    1801         159 :                 lcname = zend_str_tolower_dup(Z_STRVAL(class_name->u.constant), Z_STRLEN(class_name->u.constant));
    1802             : 
    1803         300 :                 if (CG(current_import) &&
    1804         101 :                     zend_hash_find(CG(current_import), lcname, Z_STRLEN(class_name->u.constant)+1, (void**)&ns) == SUCCESS) {
    1805             :                     /* The given name is an import name. Substitute it. */
    1806          40 :                         zval_dtor(&class_name->u.constant);
    1807          40 :                         class_name->u.constant = **ns;
    1808          40 :                         zval_copy_ctor(&class_name->u.constant);
    1809         119 :                 } else if (CG(current_namespace)) {
    1810             :                         /* plain name, no import - prepend current namespace to it */
    1811         117 :                         tmp.op_type = IS_CONST;
    1812         117 :                         tmp.u.constant = *CG(current_namespace);
    1813         117 :                         zval_copy_ctor(&tmp.u.constant);
    1814         117 :                         zend_do_build_namespace_name(&tmp, &tmp, class_name TSRMLS_CC);
    1815         117 :                         *class_name = tmp;
    1816             :                 }
    1817         159 :                 efree(lcname);
    1818             :         }
    1819             : }
    1820             : /* }}} */
    1821             : 
    1822       23360 : void zend_do_fetch_class(znode *result, znode *class_name TSRMLS_DC) /* {{{ */
    1823             : {
    1824             :         long fetch_class_op_number;
    1825             :         zend_op *opline;
    1826             : 
    1827       67348 :         if (class_name->op_type == IS_CONST &&
    1828       21994 :             Z_TYPE(class_name->u.constant) == IS_STRING &&
    1829       21994 :             Z_STRLEN(class_name->u.constant) == 0) {
    1830             :                 /* Usage of namespace as class name not in namespace */
    1831           0 :                 zval_dtor(&class_name->u.constant);
    1832           0 :                 zend_error(E_COMPILE_ERROR, "Cannot use 'namespace' as a class name");
    1833           0 :                 return;
    1834             :         }
    1835             : 
    1836       23360 :         fetch_class_op_number = get_next_op_number(CG(active_op_array));
    1837       23360 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1838             : 
    1839       23360 :         opline->opcode = ZEND_FETCH_CLASS;
    1840       23360 :         SET_UNUSED(opline->op1);
    1841       23360 :         opline->extended_value = ZEND_FETCH_CLASS_GLOBAL;
    1842       23360 :         CG(catch_begin) = fetch_class_op_number;
    1843       23360 :         if (class_name->op_type == IS_CONST) {
    1844             :                 int fetch_type;
    1845             : 
    1846       21994 :                 fetch_type = zend_get_class_fetch_type(class_name->u.constant.value.str.val, class_name->u.constant.value.str.len);
    1847       21994 :                 switch (fetch_type) {
    1848             :                         case ZEND_FETCH_CLASS_SELF:
    1849             :                         case ZEND_FETCH_CLASS_PARENT:
    1850             :                         case ZEND_FETCH_CLASS_STATIC:
    1851        5391 :                                 SET_UNUSED(opline->op2);
    1852        5391 :                                 opline->extended_value = fetch_type;
    1853        5391 :                                 zval_dtor(&class_name->u.constant);
    1854        5391 :                                 break;
    1855             :                         default:
    1856       16603 :                                 zend_resolve_class_name(class_name, &opline->extended_value, 0 TSRMLS_CC);
    1857       16603 :                                 opline->op2 = *class_name;
    1858             :                                 break;
    1859             :                 }
    1860             :         } else {
    1861        1366 :                 opline->op2 = *class_name;
    1862             :         }
    1863       23360 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    1864       23360 :         opline->result.u.EA.type = opline->extended_value;
    1865       23360 :         opline->result.op_type = IS_VAR; /* FIXME: Hack so that INIT_FCALL_BY_NAME still knows this is a class */
    1866       23360 :         *result = opline->result;
    1867             : }
    1868             : /* }}} */
    1869             : 
    1870          24 : void zend_do_label(znode *label TSRMLS_DC) /* {{{ */
    1871             : {
    1872          24 :         zend_op_array *oparray = CG(active_op_array);
    1873             :         zend_label dest;
    1874             : 
    1875          24 :         if (!CG(labels)) {
    1876          14 :                 ALLOC_HASHTABLE(CG(labels));
    1877          14 :                 zend_hash_init(CG(labels), 4, NULL, NULL, 0);
    1878             :         }
    1879             : 
    1880          24 :         dest.brk_cont = oparray->current_brk_cont;
    1881          24 :         dest.opline_num = get_next_op_number(oparray);
    1882             : 
    1883          24 :         if (zend_hash_add(CG(labels), Z_STRVAL(label->u.constant), Z_STRLEN(label->u.constant) + 1, (void**)&dest, sizeof(zend_label), NULL) == FAILURE) {
    1884           0 :                 zend_error(E_COMPILE_ERROR, "Label '%s' already defined", Z_STRVAL(label->u.constant));
    1885             :         }
    1886             : 
    1887             :         /* Done with label now */
    1888          24 :         zval_dtor(&label->u.constant);
    1889          24 : }
    1890             : /* }}} */
    1891             : 
    1892          39 : void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline, int pass2 TSRMLS_DC) /* {{{ */
    1893             : {
    1894             :         zend_label *dest;
    1895             :         long current, distance;
    1896             : 
    1897          68 :         if (CG(labels) == NULL ||
    1898          29 :                 zend_hash_find(CG(labels), Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant)+1, (void**)&dest) == FAILURE) {
    1899             : 
    1900          16 :                 if (pass2) {
    1901           1 :                         CG(in_compilation) = 1;
    1902           1 :                         CG(active_op_array) = op_array;
    1903           1 :                         CG(zend_lineno) = opline->lineno;
    1904           1 :                         zend_error(E_COMPILE_ERROR, "'goto' to undefined label '%s'", Z_STRVAL(opline->op2.u.constant));
    1905             :                 } else {
    1906             :                         /* Label is not defined. Delay to pass 2. */
    1907          15 :                         INC_BPC(op_array);
    1908          15 :                         return;
    1909             :                 }
    1910             :         }
    1911             : 
    1912          23 :         opline->op1.u.opline_num = dest->opline_num;
    1913          23 :         zval_dtor(&opline->op2.u.constant);
    1914             : 
    1915             :         /* Check that we are not moving into loop or switch */
    1916          23 :         current = opline->extended_value;
    1917          26 :         for (distance = 0; current != dest->brk_cont; distance++) {
    1918           7 :                 if (current == -1) {
    1919           4 :                         if (pass2) {
    1920           2 :                                 CG(in_compilation) = 1;
    1921           2 :                                 CG(active_op_array) = op_array;
    1922           2 :                                 CG(zend_lineno) = opline->lineno;
    1923             :                         }
    1924           4 :                         zend_error(E_COMPILE_ERROR, "'goto' into loop or switch statement is disallowed");
    1925             :                 }
    1926           3 :                 current = op_array->brk_cont_array[current].parent;
    1927             :         }
    1928             : 
    1929          19 :         if (distance == 0) {
    1930             :                 /* Nothing to break out of, optimize to ZEND_JMP */
    1931          17 :                 opline->opcode = ZEND_JMP;
    1932          17 :                 opline->extended_value = 0;
    1933          17 :                 SET_UNUSED(opline->op2);
    1934             :         } else {
    1935             :                 /* Set real break distance */
    1936           2 :                 ZVAL_LONG(&opline->op2.u.constant, distance);
    1937             :         }
    1938             : 
    1939          19 :         if (pass2) {
    1940          12 :                 DEC_BPC(op_array);
    1941             :         }
    1942             : }
    1943             : /* }}} */
    1944             : 
    1945          24 : void zend_do_goto(const znode *label TSRMLS_DC) /* {{{ */
    1946             : {
    1947          24 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1948             : 
    1949          24 :         opline->opcode = ZEND_GOTO;
    1950          24 :         opline->extended_value = CG(active_op_array)->current_brk_cont;
    1951          24 :         SET_UNUSED(opline->op1);
    1952          24 :         opline->op2 = *label;
    1953          24 :         zend_resolve_goto_label(CG(active_op_array), opline, 0 TSRMLS_CC);
    1954          22 : }
    1955             : /* }}} */
    1956             : 
    1957       65600 : void zend_release_labels(TSRMLS_D) /* {{{ */
    1958             : {
    1959       65600 :         if (CG(labels)) {
    1960          10 :                 zend_hash_destroy(CG(labels));
    1961          10 :                 FREE_HASHTABLE(CG(labels));
    1962             :         }
    1963       65600 :         if (!zend_stack_is_empty(&CG(labels_stack))) {
    1964             :                 HashTable **pht;
    1965             : 
    1966       36213 :                 zend_stack_top(&CG(labels_stack), (void**)&pht);
    1967       36213 :                 CG(labels) = *pht;
    1968       36213 :                 zend_stack_del_top(&CG(labels_stack));
    1969             :         } else {
    1970       29387 :                 CG(labels) = NULL;
    1971             :         }
    1972       65600 : }
    1973             : /* }}} */
    1974             : 
    1975        1043 : void zend_do_build_full_name(znode *result, znode *prefix, znode *name, int is_class_member TSRMLS_DC) /* {{{ */
    1976             : {
    1977             :         zend_uint length;
    1978             : 
    1979        1043 :         if (!result) {
    1980        1043 :                 result = prefix;
    1981             :         } else {
    1982           0 :                 *result = *prefix;
    1983             :         }
    1984             : 
    1985        1043 :         if (is_class_member) {
    1986         339 :                 length = sizeof("::")-1 + result->u.constant.value.str.len + name->u.constant.value.str.len;
    1987         339 :                 result->u.constant.value.str.val = erealloc(result->u.constant.value.str.val, length+1);
    1988         339 :                 memcpy(&result->u.constant.value.str.val[result->u.constant.value.str.len], "::", sizeof("::")-1);
    1989         339 :                 memcpy(&result->u.constant.value.str.val[result->u.constant.value.str.len + sizeof("::")-1], name->u.constant.value.str.val, name->u.constant.value.str.len+1);
    1990         339 :                 STR_FREE(name->u.constant.value.str.val);
    1991         339 :                 result->u.constant.value.str.len = length;
    1992             :         } else {
    1993         704 :                 length = sizeof("\\")-1 + result->u.constant.value.str.len + name->u.constant.value.str.len;
    1994         704 :                 result->u.constant.value.str.val = erealloc(result->u.constant.value.str.val, length+1);
    1995         704 :                 memcpy(&result->u.constant.value.str.val[result->u.constant.value.str.len], "\\", sizeof("\\")-1);
    1996         704 :                 memcpy(&result->u.constant.value.str.val[result->u.constant.value.str.len + sizeof("\\")-1], name->u.constant.value.str.val, name->u.constant.value.str.len+1);
    1997         704 :                 STR_FREE(name->u.constant.value.str.val);
    1998         704 :                 result->u.constant.value.str.len = length;
    1999             :         }
    2000        1043 : }
    2001             : /* }}} */
    2002             : 
    2003       10626 : int zend_do_begin_class_member_function_call(znode *class_name, znode *method_name TSRMLS_DC) /* {{{ */
    2004             : {
    2005             :         znode class_node;
    2006       10626 :         unsigned char *ptr = NULL;
    2007             :         zend_op *opline;
    2008       10626 :         ulong fetch_type = 0;
    2009             : 
    2010       10626 :         if (method_name->op_type == IS_CONST) {
    2011       10595 :                 char *lcname = zend_str_tolower_dup(Z_STRVAL(method_name->u.constant), Z_STRLEN(method_name->u.constant));
    2012       11761 :                 if ((sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1) == Z_STRLEN(method_name->u.constant) &&
    2013        1166 :                         memcmp(lcname, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1) == 0) {
    2014         989 :                         zval_dtor(&method_name->u.constant);
    2015         989 :                         SET_UNUSED(*method_name);
    2016             :                 }
    2017       10595 :                 efree(lcname);
    2018             :         }
    2019             : 
    2020       26618 :         if (class_name->op_type == IS_CONST &&
    2021       10590 :                         ZEND_FETCH_CLASS_DEFAULT == zend_get_class_fetch_type(Z_STRVAL(class_name->u.constant), Z_STRLEN(class_name->u.constant))) {
    2022        5402 :                 fetch_type = ZEND_FETCH_CLASS_GLOBAL;
    2023        5402 :                 zend_resolve_class_name(class_name, &fetch_type, 1 TSRMLS_CC);
    2024        5402 :                 class_node = *class_name;
    2025             :         } else {
    2026        5224 :                 zend_do_fetch_class(&class_node, class_name TSRMLS_CC);
    2027             :         }
    2028       10626 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2029       10626 :         opline->opcode = ZEND_INIT_STATIC_METHOD_CALL;
    2030       10626 :         opline->op1 = class_node;
    2031       10626 :         opline->op2 = *method_name;
    2032             : 
    2033       10626 :         zend_stack_push(&CG(function_call_stack), (void *) &ptr, sizeof(zend_function *));
    2034       10626 :         zend_do_extended_fcall_begin(TSRMLS_C);
    2035       10626 :         return 1; /* Dynamic */
    2036             : }
    2037             : /* }}} */
    2038             : 
    2039      370980 : void zend_do_end_function_call(znode *function_name, znode *result, const znode *argument_list, int is_method, int is_dynamic_fcall TSRMLS_DC) /* {{{ */
    2040             : {
    2041             :         zend_op *opline;
    2042             : 
    2043      370980 :         if (is_method && function_name && function_name->op_type == IS_UNUSED) {
    2044             :                 /* clone */
    2045           0 :                 if (Z_LVAL(argument_list->u.constant) != 0) {
    2046           0 :                         zend_error(E_WARNING, "Clone method does not require arguments");
    2047             :                 }
    2048           0 :                 opline = &CG(active_op_array)->opcodes[Z_LVAL(function_name->u.constant)];
    2049             :         } else {
    2050      370980 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2051      676544 :                 if (!is_method && !is_dynamic_fcall && function_name->op_type==IS_CONST) {
    2052      305564 :                         opline->opcode = ZEND_DO_FCALL;
    2053      305564 :                         opline->op1 = *function_name;
    2054      305564 :                         ZVAL_LONG(&opline->op2.u.constant, zend_hash_func(Z_STRVAL(function_name->u.constant), Z_STRLEN(function_name->u.constant) + 1));
    2055             :                 } else {
    2056       65416 :                         opline->opcode = ZEND_DO_FCALL_BY_NAME;
    2057       65416 :                         SET_UNUSED(opline->op1);
    2058             :                 }
    2059             :         }
    2060             : 
    2061      370980 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    2062      370980 :         opline->result.op_type = IS_VAR;
    2063      370980 :         *result = opline->result;
    2064      370980 :         SET_UNUSED(opline->op2);
    2065             : 
    2066      370980 :         zend_stack_del_top(&CG(function_call_stack));
    2067      370980 :         opline->extended_value = Z_LVAL(argument_list->u.constant);
    2068      370980 : }
    2069             : /* }}} */
    2070             : 
    2071      675792 : void zend_do_pass_param(znode *param, zend_uchar op, int offset TSRMLS_DC) /* {{{ */
    2072             : {
    2073             :         zend_op *opline;
    2074      675792 :         int original_op=op;
    2075             :         zend_function **function_ptr_ptr, *function_ptr;
    2076             :         int send_by_reference;
    2077      675792 :         int send_function = 0;
    2078             : 
    2079      675792 :         zend_stack_top(&CG(function_call_stack), (void **) &function_ptr_ptr);
    2080      675792 :         function_ptr = *function_ptr_ptr;
    2081             : 
    2082      675792 :         if (original_op == ZEND_SEND_REF && !CG(allow_call_time_pass_reference)) {
    2083           2 :                 if (function_ptr &&
    2084           0 :                                 function_ptr->common.function_name &&
    2085           0 :                                 function_ptr->common.type == ZEND_USER_FUNCTION &&
    2086           0 :                                 !ARG_SHOULD_BE_SENT_BY_REF(function_ptr, (zend_uint) offset)) {
    2087           0 :                         zend_error(E_DEPRECATED,
    2088             :                                                 "Call-time pass-by-reference has been deprecated; "
    2089             :                                                 "If you would like to pass it by reference, modify the declaration of %s().  "
    2090             :                                                 "If you would like to enable call-time pass-by-reference, you can set "
    2091             :                                                 "allow_call_time_pass_reference to true in your INI file", function_ptr->common.function_name);
    2092             :                 } else {
    2093           2 :                         zend_error(E_DEPRECATED, "Call-time pass-by-reference has been deprecated");
    2094             :                 }
    2095             :         }
    2096             : 
    2097      675792 :         if (function_ptr) {
    2098      595202 :                 if (ARG_MAY_BE_SENT_BY_REF(function_ptr, (zend_uint) offset)) {
    2099         356 :                         if (param->op_type & (IS_VAR|IS_CV)) {
    2100         320 :                                 send_by_reference = 1;
    2101         320 :                                 if (op == ZEND_SEND_VAR && zend_is_function_or_method_call(param)) {
    2102             :                                         /* Method call */
    2103           4 :                                         op = ZEND_SEND_VAR_NO_REF;
    2104           4 :                                         send_function = ZEND_ARG_SEND_FUNCTION | ZEND_ARG_SEND_SILENT;
    2105             :                                 }
    2106             :                         } else {
    2107          36 :                                 op = ZEND_SEND_VAL;
    2108          36 :                                 send_by_reference = 0;
    2109             :                         }
    2110             :                 } else {
    2111      594846 :                         send_by_reference = ARG_SHOULD_BE_SENT_BY_REF(function_ptr, (zend_uint) offset) ? ZEND_ARG_SEND_BY_REF : 0;
    2112             :                 }
    2113             :         } else {
    2114       80590 :                 send_by_reference = 0;
    2115             :         }
    2116             : 
    2117      742896 :         if (op == ZEND_SEND_VAR && zend_is_function_or_method_call(param)) {
    2118             :                 /* Method call */
    2119       67104 :                 op = ZEND_SEND_VAR_NO_REF;
    2120       67104 :                 send_function = ZEND_ARG_SEND_FUNCTION;
    2121      608688 :         } else if (op == ZEND_SEND_VAL && (param->op_type & (IS_VAR|IS_CV))) {
    2122        2686 :                 op = ZEND_SEND_VAR_NO_REF;
    2123             :         }
    2124             : 
    2125      675792 :         if (op!=ZEND_SEND_VAR_NO_REF && send_by_reference==ZEND_ARG_SEND_BY_REF) {
    2126             :                 /* change to passing by reference */
    2127       73475 :                 switch (param->op_type) {
    2128             :                         case IS_VAR:
    2129             :                         case IS_CV:
    2130       73469 :                                 op = ZEND_SEND_REF;
    2131       73469 :                                 break;
    2132             :                         default:
    2133           6 :                                 zend_error(E_COMPILE_ERROR, "Only variables can be passed by reference");
    2134             :                                 break;
    2135             :                 }
    2136             :         }
    2137             : 
    2138      675786 :         if (original_op == ZEND_SEND_VAR) {
    2139      376781 :                 switch (op) {
    2140             :                         case ZEND_SEND_VAR_NO_REF:
    2141       67108 :                                 zend_do_end_variable_parse(param, BP_VAR_R, 0 TSRMLS_CC);
    2142       67108 :                                 break;
    2143             :                         case ZEND_SEND_VAR:
    2144      236206 :                                 if (function_ptr) {
    2145      195214 :                                         zend_do_end_variable_parse(param, BP_VAR_R, 0 TSRMLS_CC);
    2146             :                                 } else {
    2147       40992 :                                         zend_do_end_variable_parse(param, BP_VAR_FUNC_ARG, offset TSRMLS_CC);
    2148             :                                 }
    2149      236205 :                                 break;
    2150             :                         case ZEND_SEND_REF:
    2151       73467 :                                 zend_do_end_variable_parse(param, BP_VAR_W, 0 TSRMLS_CC);
    2152             :                                 break;
    2153             :                 }
    2154             :         }
    2155             : 
    2156      675785 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2157             : 
    2158      675785 :         if (op == ZEND_SEND_VAR_NO_REF) {
    2159       69794 :                 if (function_ptr) {
    2160       68114 :                         opline->extended_value = ZEND_ARG_COMPILE_TIME_BOUND | send_by_reference | send_function;
    2161             :                 } else {
    2162        1680 :                         opline->extended_value = send_function;
    2163             :                 }
    2164             :         } else {
    2165      605991 :                 if (function_ptr) {
    2166      527081 :                         opline->extended_value = ZEND_DO_FCALL;
    2167             :                 } else {
    2168       78910 :                         opline->extended_value = ZEND_DO_FCALL_BY_NAME;
    2169             :                 }
    2170             :         }
    2171      675785 :         opline->opcode = op;
    2172      675785 :         opline->op1 = *param;
    2173      675785 :         opline->op2.u.opline_num = offset;
    2174      675785 :         SET_UNUSED(opline->op2);
    2175      675785 : }
    2176             : /* }}} */
    2177             : 
    2178       86710 : static int generate_free_switch_expr(const zend_switch_entry *switch_entry TSRMLS_DC) /* {{{ */
    2179             : {
    2180             :         zend_op *opline;
    2181             : 
    2182       86710 :         if (switch_entry->cond.op_type != IS_VAR && switch_entry->cond.op_type != IS_TMP_VAR) {
    2183       86685 :                 return (switch_entry->cond.op_type == IS_UNUSED);
    2184             :         }
    2185             : 
    2186          25 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2187             : 
    2188          25 :         opline->opcode = (switch_entry->cond.op_type == IS_TMP_VAR) ? ZEND_FREE : ZEND_SWITCH_FREE;
    2189          25 :         opline->op1 = switch_entry->cond;
    2190          25 :         SET_UNUSED(opline->op2);
    2191          25 :         opline->extended_value = 0;
    2192          25 :         return 0;
    2193             : }
    2194             : /* }}} */
    2195             : 
    2196       98208 : static int generate_free_foreach_copy(const zend_op *foreach_copy TSRMLS_DC) /* {{{ */
    2197             : {
    2198             :         zend_op *opline;
    2199             : 
    2200             :         /* If we reach the seperator then stop applying the stack */
    2201       98208 :         if (foreach_copy->result.op_type == IS_UNUSED && foreach_copy->op1.op_type == IS_UNUSED) {
    2202       86575 :                 return 1;
    2203             :         }
    2204             : 
    2205       11633 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2206             : 
    2207       11633 :         opline->opcode = (foreach_copy->result.op_type == IS_TMP_VAR) ? ZEND_FREE : ZEND_SWITCH_FREE;
    2208       11633 :         opline->op1 = foreach_copy->result;
    2209       11633 :         SET_UNUSED(opline->op2);
    2210       11633 :         opline->extended_value = 1;
    2211             : 
    2212       11633 :         if (foreach_copy->op1.op_type != IS_UNUSED) {
    2213           3 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2214             : 
    2215           3 :                 opline->opcode = (foreach_copy->op1.op_type == IS_TMP_VAR) ? ZEND_FREE : ZEND_SWITCH_FREE;
    2216           3 :                 opline->op1 = foreach_copy->op1;
    2217           3 :                 SET_UNUSED(opline->op2);
    2218           3 :                 opline->extended_value = 0;
    2219             :         }
    2220             : 
    2221       11633 :         return 0;
    2222             : }
    2223             : /* }}} */
    2224             : 
    2225      116575 : void zend_do_return(znode *expr, int do_end_vparse TSRMLS_DC) /* {{{ */
    2226             : {
    2227             :         zend_op *opline;
    2228             :         int start_op_number, end_op_number;
    2229             : 
    2230      116575 :         if (do_end_vparse) {
    2231       26850 :                 if (CG(active_op_array)->return_reference && !zend_is_function_or_method_call(expr)) {
    2232          27 :                         zend_do_end_variable_parse(expr, BP_VAR_W, 0 TSRMLS_CC);
    2233             :                 } else {
    2234       26796 :                         zend_do_end_variable_parse(expr, BP_VAR_R, 0 TSRMLS_CC);
    2235             :                 }
    2236             :         }
    2237             : 
    2238      116575 :         start_op_number = get_next_op_number(CG(active_op_array));
    2239             : 
    2240             : #ifdef ZTS
    2241             :         zend_stack_apply_with_argument(&CG(switch_cond_stack), ZEND_STACK_APPLY_TOPDOWN, (int (*)(void *element, void *)) generate_free_switch_expr TSRMLS_CC);
    2242             :         zend_stack_apply_with_argument(&CG(foreach_copy_stack), ZEND_STACK_APPLY_TOPDOWN, (int (*)(void *element, void *)) generate_free_foreach_copy TSRMLS_CC);
    2243             : #else
    2244      116575 :         zend_stack_apply(&CG(switch_cond_stack), ZEND_STACK_APPLY_TOPDOWN, (int (*)(void *element)) generate_free_switch_expr);
    2245      116575 :         zend_stack_apply(&CG(foreach_copy_stack), ZEND_STACK_APPLY_TOPDOWN, (int (*)(void *element)) generate_free_foreach_copy);
    2246             : #endif
    2247             : 
    2248      116575 :         end_op_number = get_next_op_number(CG(active_op_array));
    2249      233653 :         while (start_op_number < end_op_number) {
    2250         503 :                 CG(active_op_array)->opcodes[start_op_number].op1.u.EA.type = EXT_TYPE_FREE_ON_RETURN;
    2251         503 :                 start_op_number++;
    2252             :         }
    2253             : 
    2254      116575 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2255             : 
    2256      116575 :         opline->opcode = ZEND_RETURN;
    2257             : 
    2258      116575 :         if (expr) {
    2259       79154 :                 opline->op1 = *expr;
    2260             : 
    2261       79154 :                 if (do_end_vparse && zend_is_function_or_method_call(expr)) {
    2262        8154 :                         opline->extended_value = ZEND_RETURNS_FUNCTION;
    2263             :                 }
    2264             :         } else {
    2265       37421 :                 opline->op1.op_type = IS_CONST;
    2266       37421 :                 INIT_ZVAL(opline->op1.u.constant);
    2267             :         }
    2268             : 
    2269      116575 :         SET_UNUSED(opline->op2);
    2270      116575 : }
    2271             : /* }}} */
    2272             : 
    2273        2055 : static int zend_add_try_element(zend_uint try_op TSRMLS_DC) /* {{{ */
    2274             : {
    2275        2055 :         int try_catch_offset = CG(active_op_array)->last_try_catch++;
    2276             : 
    2277        2055 :         CG(active_op_array)->try_catch_array = erealloc(CG(active_op_array)->try_catch_array, sizeof(zend_try_catch_element)*CG(active_op_array)->last_try_catch);
    2278        2055 :         CG(active_op_array)->try_catch_array[try_catch_offset].try_op = try_op;
    2279        2055 :         return try_catch_offset;
    2280             : }
    2281             : /* }}} */
    2282             : 
    2283        2055 : static void zend_add_catch_element(int offset, zend_uint catch_op TSRMLS_DC) /* {{{ */
    2284             : {
    2285        2055 :         CG(active_op_array)->try_catch_array[offset].catch_op = catch_op;
    2286        2055 : }
    2287             : /* }}} */
    2288             : 
    2289        2055 : void zend_do_first_catch(znode *open_parentheses TSRMLS_DC) /* {{{ */
    2290             : {
    2291        2055 :         open_parentheses->u.opline_num = get_next_op_number(CG(active_op_array));
    2292        2055 : }
    2293             : /* }}} */
    2294             : 
    2295        2055 : void zend_initialize_try_catch_element(const znode *try_token TSRMLS_DC) /* {{{ */
    2296             : {
    2297        2055 :         int jmp_op_number = get_next_op_number(CG(active_op_array));
    2298        2055 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2299             :         zend_llist jmp_list;
    2300             :         zend_llist *jmp_list_ptr;
    2301             : 
    2302        2055 :         opline->opcode = ZEND_JMP;
    2303        2055 :         SET_UNUSED(opline->op1);
    2304        2055 :         SET_UNUSED(opline->op2);
    2305             :         /* save for backpatching */
    2306             : 
    2307        2055 :         zend_llist_init(&jmp_list, sizeof(int), NULL, 0);
    2308        2055 :         zend_stack_push(&CG(bp_stack), (void *) &jmp_list, sizeof(zend_llist));
    2309        2055 :         zend_stack_top(&CG(bp_stack), (void **) &jmp_list_ptr);
    2310        2055 :         zend_llist_add_element(jmp_list_ptr, &jmp_op_number);
    2311             : 
    2312        2055 :         zend_add_catch_element(try_token->u.opline_num, get_next_op_number(CG(active_op_array)) TSRMLS_CC);
    2313        2055 : }
    2314             : /* }}} */
    2315             : 
    2316        2055 : void zend_do_mark_last_catch(const znode *first_catch, const znode *last_additional_catch TSRMLS_DC) /* {{{ */
    2317             : {
    2318        2055 :         CG(active_op_array)->last--;
    2319        2055 :         zend_do_if_end(TSRMLS_C);
    2320        2055 :         if (last_additional_catch->u.opline_num == -1) {
    2321        2048 :                 CG(active_op_array)->opcodes[first_catch->u.opline_num].op1.u.EA.type = 1;
    2322        2048 :                 CG(active_op_array)->opcodes[first_catch->u.opline_num].extended_value = get_next_op_number(CG(active_op_array));
    2323             :         } else {
    2324           7 :                 CG(active_op_array)->opcodes[last_additional_catch->u.opline_num].op1.u.EA.type = 1;
    2325           7 :                 CG(active_op_array)->opcodes[last_additional_catch->u.opline_num].extended_value = get_next_op_number(CG(active_op_array));
    2326             :         }
    2327        2055 :         DEC_BPC(CG(active_op_array));
    2328        2055 : }
    2329             : /* }}} */
    2330             : 
    2331        2055 : void zend_do_try(znode *try_token TSRMLS_DC) /* {{{ */
    2332             : {
    2333        2055 :         try_token->u.opline_num = zend_add_try_element(get_next_op_number(CG(active_op_array)) TSRMLS_CC);
    2334        2055 :         INC_BPC(CG(active_op_array));
    2335        2055 : }
    2336             : /* }}} */
    2337             : 
    2338        2062 : void zend_do_begin_catch(znode *try_token, znode *class_name, const znode *catch_var, znode *first_catch TSRMLS_DC) /* {{{ */
    2339             : {
    2340             :         long catch_op_number;
    2341             :         zend_op *opline;
    2342             :         znode catch_class;
    2343             : 
    2344        2062 :         zend_do_fetch_class(&catch_class, class_name TSRMLS_CC);
    2345             : 
    2346        2062 :         catch_op_number = get_next_op_number(CG(active_op_array));
    2347        2062 :         if (catch_op_number > 0) {
    2348        2062 :                 opline = &CG(active_op_array)->opcodes[catch_op_number-1];
    2349        2062 :                 if (opline->opcode == ZEND_FETCH_CLASS) {
    2350        2062 :                         opline->extended_value |= ZEND_FETCH_CLASS_NO_AUTOLOAD;
    2351             :                 }
    2352             :         }
    2353             : 
    2354        2062 :         if (first_catch) {
    2355        2055 :                 first_catch->u.opline_num = catch_op_number;
    2356             :         }
    2357             : 
    2358        2062 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2359        2062 :         opline->opcode = ZEND_CATCH;
    2360        2062 :         opline->op1 = catch_class;
    2361             : /*      SET_UNUSED(opline->op1); */ /* FIXME: Define IS_CLASS or something like that */
    2362        2062 :         opline->op2.op_type = IS_CV;
    2363        2062 :         opline->op2.u.var = lookup_cv(CG(active_op_array), catch_var->u.constant.value.str.val, catch_var->u.constant.value.str.len);
    2364        2062 :         opline->op2.u.EA.type = 0;
    2365        2062 :         opline->op1.u.EA.type = 0; /* 1 means it's the last catch in the block */
    2366             : 
    2367        2062 :         try_token->u.opline_num = catch_op_number;
    2368        2062 : }
    2369             : /* }}} */
    2370             : 
    2371        2062 : void zend_do_end_catch(const znode *try_token TSRMLS_DC) /* {{{ */
    2372             : {
    2373        2062 :         int jmp_op_number = get_next_op_number(CG(active_op_array));
    2374        2062 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2375             :         zend_llist *jmp_list_ptr;
    2376             : 
    2377        2062 :         opline->opcode = ZEND_JMP;
    2378        2062 :         SET_UNUSED(opline->op1);
    2379        2062 :         SET_UNUSED(opline->op2);
    2380             :         /* save for backpatching */
    2381             : 
    2382        2062 :         zend_stack_top(&CG(bp_stack), (void **) &jmp_list_ptr);
    2383        2062 :         zend_llist_add_element(jmp_list_ptr, &jmp_op_number);
    2384             : 
    2385        2062 :         CG(active_op_array)->opcodes[try_token->u.opline_num].extended_value = get_next_op_number(CG(active_op_array));
    2386        2062 : }
    2387             : /* }}} */
    2388             : 
    2389         262 : void zend_do_throw(const znode *expr TSRMLS_DC) /* {{{ */
    2390             : {
    2391             :         zend_op *opline;
    2392             : 
    2393         262 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2394         262 :         opline->opcode = ZEND_THROW;
    2395         262 :         opline->op1 = *expr;
    2396         262 :         SET_UNUSED(opline->op2);
    2397         262 : }
    2398             : /* }}} */
    2399             : 
    2400    21687865 : ZEND_API void function_add_ref(zend_function *function) /* {{{ */
    2401             : {
    2402    21687865 :         if (function->type == ZEND_USER_FUNCTION) {
    2403        1356 :                 zend_op_array *op_array = &function->op_array;
    2404             : 
    2405        1356 :                 (*op_array->refcount)++;
    2406        1356 :                 if (op_array->static_variables) {
    2407           1 :                         HashTable *static_variables = op_array->static_variables;
    2408             :                         zval *tmp_zval;
    2409             : 
    2410           1 :                         ALLOC_HASHTABLE(op_array->static_variables);
    2411           1 :                         zend_hash_init(op_array->static_variables, zend_hash_num_elements(static_variables), NULL, ZVAL_PTR_DTOR, 0);
    2412           1 :                         zend_hash_copy(op_array->static_variables, static_variables, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_zval, sizeof(zval *));
    2413             :                 }
    2414             :         }
    2415    21687865 : }
    2416             : /* }}} */
    2417             : 
    2418     1239943 : static void do_inherit_parent_constructor(zend_class_entry *ce) /* {{{ */
    2419             : {
    2420             :         zend_function *function;
    2421             : 
    2422     1239943 :         if (!ce->parent) {
    2423           0 :                 return;
    2424             :         }
    2425             : 
    2426             :         /* You cannot change create_object */
    2427     1239943 :         ce->create_object = ce->parent->create_object;
    2428             : 
    2429             :         /* Inherit special functions if needed */
    2430     1239943 :         if (!ce->get_iterator) {
    2431      794922 :                 ce->get_iterator = ce->parent->get_iterator;
    2432             :         }
    2433     1239943 :         if (!ce->iterator_funcs.funcs) {
    2434      794954 :                 ce->iterator_funcs.funcs = ce->parent->iterator_funcs.funcs;
    2435             :         }
    2436     1239943 :         if (!ce->__get) {
    2437     1239939 :                 ce->__get   = ce->parent->__get;
    2438             :         }
    2439     1239943 :         if (!ce->__set) {
    2440     1239937 :                 ce->__set = ce->parent->__set;
    2441             :         }
    2442     1239943 :         if (!ce->__unset) {
    2443     1239939 :                 ce->__unset = ce->parent->__unset;
    2444             :         }
    2445     1239943 :         if (!ce->__isset) {
    2446     1239939 :                 ce->__isset = ce->parent->__isset;
    2447             :         }
    2448     1239943 :         if (!ce->__call) {
    2449     1239933 :                 ce->__call = ce->parent->__call;
    2450             :         }
    2451     1239943 :         if (!ce->__callstatic) {
    2452     1239942 :                 ce->__callstatic = ce->parent->__callstatic;
    2453             :         }
    2454     1239943 :         if (!ce->__tostring) {
    2455     1123890 :                 ce->__tostring = ce->parent->__tostring;
    2456             :         }
    2457     1239943 :         if (!ce->clone) {
    2458     1239939 :                 ce->clone = ce->parent->clone;
    2459             :         }
    2460     1239943 :         if(!ce->serialize) {
    2461     1027092 :                 ce->serialize = ce->parent->serialize;
    2462             :         }
    2463     1239943 :         if(!ce->unserialize) {
    2464     1027092 :                 ce->unserialize = ce->parent->unserialize;
    2465             :         }
    2466     1239943 :         if (!ce->destructor) {
    2467     1181854 :                 ce->destructor   = ce->parent->destructor;
    2468             :         }
    2469     1239943 :         if (ce->constructor) {
    2470      678092 :                 if (ce->parent->constructor && ce->parent->constructor->common.fn_flags & ZEND_ACC_FINAL) {
    2471           6 :                         zend_error(E_ERROR, "Cannot override final %s::%s() with %s::%s()",
    2472           4 :                                 ce->parent->name, ce->parent->constructor->common.function_name,
    2473           2 :                                 ce->name, ce->constructor->common.function_name
    2474             :                                 );
    2475             :                 }
    2476      678090 :                 return;
    2477             :         }
    2478             : 
    2479      561851 :         if (zend_hash_find(&ce->parent->function_table, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME), (void **)&function)==SUCCESS) {
    2480             :                 /* inherit parent's constructor */
    2481      406370 :                 zend_hash_update(&ce->function_table, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME), function, sizeof(zend_function), NULL);
    2482      406370 :                 function_add_ref(function);
    2483             :         } else {
    2484             :                 /* Don't inherit the old style constructor if we already have the new style constructor */
    2485             :                 char *lc_class_name;
    2486             :                 char *lc_parent_class_name;
    2487             : 
    2488      155481 :                 lc_class_name = zend_str_tolower_dup(ce->name, ce->name_length);
    2489      155481 :                 if (!zend_hash_exists(&ce->function_table, lc_class_name, ce->name_length+1)) {
    2490      155475 :                         lc_parent_class_name = zend_str_tolower_dup(ce->parent->name, ce->parent->name_length);
    2491      310911 :                         if (!zend_hash_exists(&ce->function_table, lc_parent_class_name, ce->parent->name_length+1) && 
    2492      155436 :                                         zend_hash_find(&ce->parent->function_table, lc_parent_class_name, ce->parent->name_length+1, (void **)&function)==SUCCESS) {
    2493           0 :                                 if (function->common.fn_flags & ZEND_ACC_CTOR) {
    2494             :                                         /* inherit parent's constructor */
    2495           0 :                                         zend_hash_update(&ce->function_table, lc_parent_class_name, ce->parent->name_length+1, function, sizeof(zend_function), NULL);
    2496           0 :                                         function_add_ref(function);
    2497             :                                 }
    2498             :                         }
    2499      155475 :                         efree(lc_parent_class_name);
    2500             :                 }
    2501      155481 :                 efree(lc_class_name);
    2502             :         }
    2503      561851 :         ce->constructor = ce->parent->constructor;
    2504             : }
    2505             : /* }}} */
    2506             : 
    2507          56 : char *zend_visibility_string(zend_uint fn_flags) /* {{{ */
    2508             : {
    2509          56 :         if (fn_flags & ZEND_ACC_PRIVATE) {
    2510          19 :                 return "private";
    2511             :         }
    2512          37 :         if (fn_flags & ZEND_ACC_PROTECTED) {
    2513          26 :                 return "protected";
    2514             :         }
    2515          11 :         if (fn_flags & ZEND_ACC_PUBLIC) {
    2516          11 :                 return "public";
    2517             :         }
    2518           0 :         return "";
    2519             : }
    2520             : /* }}} */
    2521             : 
    2522    21281440 : static void do_inherit_method(zend_function *function) /* {{{ */
    2523             : {
    2524             :         /* The class entry of the derived function intentionally remains the same
    2525             :          * as that of the parent class.  That allows us to know in which context
    2526             :          * we're running, and handle private method calls properly.
    2527             :          */
    2528    21281440 :         function_add_ref(function);
    2529    21281440 : }
    2530             : /* }}} */
    2531             : 
    2532     5387238 : static zend_bool zend_do_perform_implementation_check(const zend_function *fe, const zend_function *proto TSRMLS_DC) /* {{{ */
    2533             : {
    2534             :         zend_uint i;
    2535             : 
    2536             :         /* If it's a user function then arg_info == NULL means we don't have any parameters but
    2537             :          * we still need to do the arg number checks.  We are only willing to ignore this for internal
    2538             :          * functions because extensions don't always define arg_info.
    2539             :          */
    2540     5387238 :         if (!proto || (!proto->common.arg_info && proto->common.type != ZEND_USER_FUNCTION)) {
    2541     3133489 :                 return 1;
    2542             :         }
    2543             : 
    2544             :         /* Checks for constructors only if they are declared in an interface */
    2545     2253749 :         if ((fe->common.fn_flags & ZEND_ACC_CTOR) && (proto->common.scope->ce_flags & ZEND_ACC_INTERFACE) == 0) {
    2546      458340 :                 return 1;
    2547             :         }
    2548             : 
    2549             :         /* check number of arguments */
    2550     3590809 :         if (proto->common.required_num_args < fe->common.required_num_args
    2551     3590809 :                 || proto->common.num_args > fe->common.num_args) {
    2552          16 :                 return 0;
    2553             :         }
    2554             : 
    2555     3589890 :         if (fe->common.type != ZEND_USER_FUNCTION
    2556     1795393 :                 && proto->common.pass_rest_by_reference
    2557     1794497 :                 && !fe->common.pass_rest_by_reference) {
    2558           0 :                 return 0;
    2559             :         }
    2560             : 
    2561             :         /* by-ref constraints on return values are covariant */
    2562     1795393 :         if (proto->common.return_reference && !fe->common.return_reference) {
    2563           1 :                 return 0;
    2564             :         }
    2565             : 
    2566     2743366 :         for (i=0; i < proto->common.num_args; i++) {
    2567      947982 :                 if (ZEND_LOG_XOR(fe->common.arg_info[i].class_name, proto->common.arg_info[i].class_name)) {
    2568             :                         /* Only one has a type hint and the other one doesn't */
    2569           3 :                         return 0;
    2570             :                 }
    2571     1895979 :                 if (fe->common.arg_info[i].class_name
    2572      948000 :                         && strcasecmp(fe->common.arg_info[i].class_name, proto->common.arg_info[i].class_name)!=0) {
    2573             :                         char *colon;
    2574             : 
    2575           2 :                         if (fe->common.type != ZEND_USER_FUNCTION) {
    2576           0 :                                 return 0;
    2577           4 :                         } else if (strchr(proto->common.arg_info[i].class_name, '\\') != NULL ||
    2578           2 :                             (colon = zend_memrchr(fe->common.arg_info[i].class_name, '\\', fe->common.arg_info[i].class_name_len)) == NULL ||
    2579           0 :                             strcasecmp(colon+1, proto->common.arg_info[i].class_name) != 0) {
    2580             :                                 zend_class_entry **fe_ce, **proto_ce;
    2581             :                                 int found, found2;
    2582             :                                 
    2583           2 :                                 found = zend_lookup_class(fe->common.arg_info[i].class_name, fe->common.arg_info[i].class_name_len, &fe_ce TSRMLS_CC);
    2584           2 :                                 found2 = zend_lookup_class(proto->common.arg_info[i].class_name, proto->common.arg_info[i].class_name_len, &proto_ce TSRMLS_CC);
    2585             :                                 
    2586             :                                 /* Check for class alias */
    2587           5 :                                 if (found != SUCCESS || found2 != SUCCESS ||
    2588           1 :                                         (*fe_ce)->type == ZEND_INTERNAL_CLASS ||
    2589           1 :                                         (*proto_ce)->type == ZEND_INTERNAL_CLASS ||
    2590           1 :                                         *fe_ce != *proto_ce) {
    2591           1 :                                         return 0;
    2592             :                                 }
    2593             :                         }
    2594             :                 }
    2595      947978 :                 if (fe->common.arg_info[i].array_type_hint != proto->common.arg_info[i].array_type_hint) {
    2596             :                         /* Only one has an array type hint and the other one doesn't */
    2597           2 :                         return 0;
    2598             :                 }
    2599             : 
    2600             :                 /* by-ref constraints on arguments are invariant */
    2601      947976 :                 if (fe->common.arg_info[i].pass_by_reference != proto->common.arg_info[i].pass_by_reference) {
    2602           2 :                         return 0;
    2603             :                 }
    2604             :         }
    2605             : 
    2606     1795384 :         if (proto->common.pass_rest_by_reference) {
    2607           1 :                 for (i=proto->common.num_args; i < fe->common.num_args; i++) {
    2608           0 :                         if (!fe->common.arg_info[i].pass_by_reference) {
    2609           0 :                                 return 0;
    2610             :                         }
    2611             :                 }
    2612             :         }
    2613     1795384 :         return 1;
    2614             : }
    2615             : /* }}} */
    2616             : 
    2617    26679112 : static zend_bool do_inherit_method_check(HashTable *child_function_table, zend_function *parent, const zend_hash_key *hash_key, zend_class_entry *child_ce) /* {{{ */
    2618             : {
    2619             :         zend_uint child_flags;
    2620    26679112 :         zend_uint parent_flags = parent->common.fn_flags;
    2621             :         zend_function *child;
    2622             :         TSRMLS_FETCH();
    2623             : 
    2624    26679112 :         if (zend_hash_quick_find(child_function_table, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void **) &child)==FAILURE) {
    2625    21281440 :                 if (parent_flags & (ZEND_ACC_ABSTRACT)) {
    2626      309504 :                         child_ce->ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
    2627             :                 }
    2628    21281440 :                 return 1; /* method doesn't exist in child, copy from parent */
    2629             :         }
    2630             : 
    2631     7332799 :         if ((parent->common.scope->ce_flags & ZEND_ACC_INTERFACE) == 0
    2632             :                 && parent->common.fn_flags & ZEND_ACC_ABSTRACT
    2633     1935127 :                 && parent->common.scope != (child->common.prototype ? child->common.prototype->common.scope : child->common.scope)
    2634      464340 :                 && child->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_IMPLEMENTED_ABSTRACT)) {
    2635           0 :                 zend_error(E_COMPILE_ERROR, "Can't inherit abstract function %s::%s() (previously declared abstract in %s)", 
    2636           0 :                         parent->common.scope->name,
    2637           0 :                         child->common.function_name,
    2638           0 :                         child->common.prototype ? child->common.prototype->common.scope->name : child->common.scope->name);
    2639             :         }
    2640             : 
    2641     5397672 :         if (parent_flags & ZEND_ACC_FINAL) {
    2642           3 :                 zend_error(E_COMPILE_ERROR, "Cannot override final method %s::%s()", ZEND_FN_SCOPE_NAME(parent), child->common.function_name);
    2643             :         }
    2644             : 
    2645     5397669 :         child_flags     = child->common.fn_flags;
    2646             :         /* You cannot change from static to non static and vice versa.
    2647             :          */
    2648     5397669 :         if ((child_flags & ZEND_ACC_STATIC) != (parent_flags & ZEND_ACC_STATIC)) {
    2649           3 :                 if (child->common.fn_flags & ZEND_ACC_STATIC) {
    2650           2 :                         zend_error(E_COMPILE_ERROR, "Cannot make non static method %s::%s() static in class %s", ZEND_FN_SCOPE_NAME(parent), child->common.function_name, ZEND_FN_SCOPE_NAME(child));
    2651             :                 } else {
    2652           1 :                         zend_error(E_COMPILE_ERROR, "Cannot make static method %s::%s() non static in class %s", ZEND_FN_SCOPE_NAME(parent), child->common.function_name, ZEND_FN_SCOPE_NAME(child));
    2653             :                 }
    2654             :         }
    2655             : 
    2656             :         /* Disallow making an inherited method abstract. */
    2657     5397666 :         if ((child_flags & ZEND_ACC_ABSTRACT) && !(parent_flags & ZEND_ACC_ABSTRACT)) {
    2658           0 :                 zend_error(E_COMPILE_ERROR, "Cannot make non abstract method %s::%s() abstract in class %s", ZEND_FN_SCOPE_NAME(parent), child->common.function_name, ZEND_FN_SCOPE_NAME(child));
    2659             :         }
    2660             : 
    2661     5397666 :         if (parent_flags & ZEND_ACC_CHANGED) {
    2662           0 :                 child->common.fn_flags |= ZEND_ACC_CHANGED;
    2663             :         } else {
    2664             :                 /* Prevent derived classes from restricting access that was available in parent classes
    2665             :                  */
    2666     5397666 :                 if ((child_flags & ZEND_ACC_PPP_MASK) > (parent_flags & ZEND_ACC_PPP_MASK)) {
    2667           8 :                         zend_error(E_COMPILE_ERROR, "Access level to %s::%s() must be %s (as in class %s)%s", ZEND_FN_SCOPE_NAME(child), child->common.function_name, zend_visibility_string(parent_flags), ZEND_FN_SCOPE_NAME(parent), (parent_flags&ZEND_ACC_PUBLIC) ? "" : " or weaker");
    2668     5397692 :                 } else if (((child_flags & ZEND_ACC_PPP_MASK) < (parent_flags & ZEND_ACC_PPP_MASK))
    2669          34 :                         && ((parent_flags & ZEND_ACC_PPP_MASK) & ZEND_ACC_PRIVATE)) {
    2670          16 :                         child->common.fn_flags |= ZEND_ACC_CHANGED;
    2671             :                 }
    2672             :         }
    2673             : 
    2674     5397658 :         if (parent_flags & ZEND_ACC_PRIVATE) {
    2675          40 :                 child->common.prototype = NULL;              
    2676     5397618 :         } else if (parent_flags & ZEND_ACC_ABSTRACT) {
    2677     3810798 :                 child->common.fn_flags |= ZEND_ACC_IMPLEMENTED_ABSTRACT;
    2678     3810798 :                 child->common.prototype = parent;
    2679     1586820 :         } else if (!(parent->common.fn_flags & ZEND_ACC_CTOR) || (parent->common.prototype && (parent->common.prototype->common.scope->ce_flags & ZEND_ACC_INTERFACE))) {
    2680             :                 /* ctors only have a prototype if it comes from an interface */
    2681     1122527 :                 child->common.prototype = parent->common.prototype ? parent->common.prototype : parent;
    2682             :         }
    2683             : 
    2684     9982264 :         if (child->common.prototype && (child->common.prototype->common.fn_flags & ZEND_ACC_ABSTRACT)) {
    2685     4584610 :                 if (!zend_do_perform_implementation_check(child, child->common.prototype TSRMLS_CC)) {
    2686           4 :                         zend_error(E_COMPILE_ERROR, "Declaration of %s::%s() must be compatible with that of %s::%s()", ZEND_FN_SCOPE_NAME(child), child->common.function_name, ZEND_FN_SCOPE_NAME(child->common.prototype), child->common.prototype->common.function_name);
    2687             :                 }
    2688      813048 :         } else if (EG(error_reporting) & E_STRICT || EG(user_error_handler)) { /* Check E_STRICT (or custom error handler) before the check so that we save some time */
    2689      802628 :                 if (!zend_do_perform_implementation_check(child, parent TSRMLS_CC)) {
    2690          21 :                         zend_error(E_STRICT, "Declaration of %s::%s() should be compatible with that of %s::%s()", ZEND_FN_SCOPE_NAME(child), child->common.function_name, ZEND_FN_SCOPE_NAME(parent), parent->common.function_name);
    2691             :                 }
    2692             :         }
    2693             : 
    2694     5397654 :         return 0;
    2695             : }
    2696             : /* }}} */
    2697             : 
    2698     2937399 : static zend_bool do_inherit_property_access_check(HashTable *target_ht, zend_property_info *parent_info, const zend_hash_key *hash_key, zend_class_entry *ce) /* {{{ */
    2699             : {
    2700             :         zend_property_info *child_info;
    2701     2937399 :         zend_class_entry *parent_ce = ce->parent;
    2702             : 
    2703     2937399 :         if (parent_info->flags & (ZEND_ACC_PRIVATE|ZEND_ACC_SHADOW)) {
    2704     1218691 :                 if (zend_hash_quick_find(&ce->properties_info, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void **) &child_info)==SUCCESS) {
    2705          50 :                         child_info->flags |= ZEND_ACC_CHANGED;
    2706             :                 } else {
    2707     1218641 :                         zend_hash_quick_update(&ce->properties_info, hash_key->arKey, hash_key->nKeyLength, hash_key->h, parent_info, sizeof(zend_property_info), (void **) &child_info);
    2708     1218641 :                         if(ce->type & ZEND_INTERNAL_CLASS) {
    2709     1218483 :                                 zend_duplicate_property_info_internal(child_info);
    2710             :                         } else {
    2711         158 :                                 zend_duplicate_property_info(child_info);
    2712             :                         }
    2713     1218641 :                         child_info->flags &= ~ZEND_ACC_PRIVATE; /* it's not private anymore */
    2714     1218641 :                         child_info->flags |= ZEND_ACC_SHADOW; /* but it's a shadow of private */
    2715             :                 }
    2716     1218691 :                 return 0; /* don't copy access information to child */
    2717             :         }
    2718             : 
    2719     1718708 :         if (zend_hash_quick_find(&ce->properties_info, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void **) &child_info)==SUCCESS) {
    2720          91 :                 if ((parent_info->flags & ZEND_ACC_STATIC) != (child_info->flags & ZEND_ACC_STATIC)) {
    2721          36 :                         zend_error(E_COMPILE_ERROR, "Cannot redeclare %s%s::$%s as %s%s::$%s",
    2722          12 :                                 (parent_info->flags & ZEND_ACC_STATIC) ? "static " : "non static ", parent_ce->name, hash_key->arKey,
    2723          12 :                                 (child_info->flags & ZEND_ACC_STATIC) ? "static " : "non static ", ce->name, hash_key->arKey);
    2724             :                                 
    2725             :                 }
    2726             : 
    2727          79 :                 if(parent_info->flags & ZEND_ACC_CHANGED) {
    2728           1 :                         child_info->flags |= ZEND_ACC_CHANGED;
    2729             :                 }
    2730             : 
    2731          79 :                 if ((child_info->flags & ZEND_ACC_PPP_MASK) > (parent_info->flags & ZEND_ACC_PPP_MASK)) {
    2732           7 :                         zend_error(E_COMPILE_ERROR, "Access level to %s::$%s must be %s (as in class %s)%s", ce->name, hash_key->arKey, zend_visibility_string(parent_info->flags), parent_ce->name, (parent_info->flags&ZEND_ACC_PUBLIC) ? "" : " or weaker");
    2733          72 :                 } else if (child_info->flags & ZEND_ACC_IMPLICIT_PUBLIC) {
    2734           0 :                         if (!(parent_info->flags & ZEND_ACC_IMPLICIT_PUBLIC)) {
    2735             :                                 /* Explicitly copy the default value from the parent (if it has one) */
    2736             :                                 zval **pvalue;
    2737             :         
    2738           0 :                                 if (zend_hash_quick_find(&parent_ce->default_properties, parent_info->name, parent_info->name_length+1, parent_info->h, (void **) &pvalue) == SUCCESS) {
    2739           0 :                                         Z_ADDREF_PP(pvalue);
    2740           0 :                                         zend_hash_quick_del(&ce->default_properties, child_info->name, child_info->name_length+1, parent_info->h);
    2741           0 :                                         zend_hash_quick_update(&ce->default_properties, parent_info->name, parent_info->name_length+1, parent_info->h, pvalue, sizeof(zval *), NULL);
    2742             :                                 }
    2743             :                         }
    2744           0 :                         return 1; /* Inherit from the parent */
    2745          72 :                 } else if ((child_info->flags & ZEND_ACC_PUBLIC) && (parent_info->flags & ZEND_ACC_PROTECTED)) {
    2746             :                         char *prot_name;
    2747             :                         int prot_name_length;
    2748             : 
    2749           7 :                         zend_mangle_property_name(&prot_name, &prot_name_length, "*", 1, child_info->name, child_info->name_length, ce->type & ZEND_INTERNAL_CLASS);
    2750           7 :                         if (child_info->flags & ZEND_ACC_STATIC) {
    2751             :                                 zval **prop;
    2752             :                                 HashTable *ht;
    2753             : 
    2754           4 :                                 if (parent_ce->type != ce->type) {
    2755             :                                         /* User class extends internal class */
    2756             :                                         TSRMLS_FETCH();
    2757             : 
    2758           0 :                                         ht = CE_STATIC_MEMBERS(parent_ce);
    2759             :                                 } else {
    2760           4 :                                         ht = &parent_ce->default_static_members;
    2761             :                                 }
    2762           4 :                                 if (zend_hash_find(ht, prot_name, prot_name_length+1, (void**)&prop) == SUCCESS) {
    2763           4 :                                         zend_hash_del(&ce->default_static_members, prot_name, prot_name_length+1);
    2764             :                                 }
    2765             :                         } else {
    2766           3 :                                 zend_hash_del(&ce->default_properties, prot_name, prot_name_length+1);
    2767             :                         }
    2768           7 :                         pefree(prot_name, ce->type & ZEND_INTERNAL_CLASS);
    2769             :                 }
    2770          72 :                 return 0;       /* Don't copy from parent */
    2771             :         } else {
    2772     1718617 :                 return 1;       /* Copy from parent */
    2773             :         }
    2774             : }
    2775             : /* }}} */
    2776             : 
    2777     3153865 : static inline void do_implement_interface(zend_class_entry *ce, zend_class_entry *iface TSRMLS_DC) /* {{{ */
    2778             : {
    2779     3153865 :         if (!(ce->ce_flags & ZEND_ACC_INTERFACE) && iface->interface_gets_implemented && iface->interface_gets_implemented(iface, ce TSRMLS_CC) == FAILURE) {
    2780           0 :                 zend_error(E_CORE_ERROR, "Class %s could not implement interface %s", ce->name, iface->name);
    2781             :         }
    2782     3153862 :         if (ce == iface) {
    2783           1 :                 zend_error(E_ERROR, "Interface %s cannot implement itself", ce->name);
    2784             :         }
    2785     3153861 : }
    2786             : /* }}} */
    2787             : 
    2788     2400745 : ZEND_API void zend_do_inherit_interfaces(zend_class_entry *ce, const zend_class_entry *iface TSRMLS_DC) /* {{{ */
    2789             : {
    2790             :         /* expects interface to be contained in ce's interface list already */
    2791     2400745 :         zend_uint i, ce_num, if_num = iface->num_interfaces;
    2792             :         zend_class_entry *entry;
    2793             : 
    2794     2400745 :         if (if_num==0) {
    2795     1336589 :                 return;
    2796             :         }
    2797     1064156 :         ce_num = ce->num_interfaces;
    2798             : 
    2799     1064156 :         if (ce->type == ZEND_INTERNAL_CLASS) {
    2800     1063755 :                 ce->interfaces = (zend_class_entry **) realloc(ce->interfaces, sizeof(zend_class_entry *) * (ce_num + if_num));
    2801             :         } else {
    2802         401 :                 ce->interfaces = (zend_class_entry **) erealloc(ce->interfaces, sizeof(zend_class_entry *) * (ce_num + if_num));
    2803             :         }
    2804             : 
    2805             :         /* Inherit the interfaces, only if they're not already inherited by the class */
    2806     4527618 :         while (if_num--) {
    2807     2399306 :                 entry = iface->interfaces[if_num];
    2808     3308509 :                 for (i = 0; i < ce_num; i++) {
    2809     1315416 :                         if (ce->interfaces[i] == entry) {
    2810      406213 :                                 break;
    2811             :                         }
    2812             :                 }
    2813     2399306 :                 if (i == ce_num) {
    2814     1993093 :                         ce->interfaces[ce->num_interfaces++] = entry;
    2815             :                 }
    2816             :         }
    2817             : 
    2818             :         /* and now call the implementing handlers */
    2819     4121405 :         while (ce_num < ce->num_interfaces) {
    2820     1993093 :                 do_implement_interface(ce, ce->interfaces[ce_num++] TSRMLS_CC);
    2821             :         }
    2822             : }
    2823             : /* }}} */
    2824             : 
    2825         132 : static int inherit_static_prop(zval **p TSRMLS_DC, int num_args, va_list args, const zend_hash_key *key) /* {{{ */
    2826             : {
    2827         132 :         HashTable *target = va_arg(args, HashTable*);
    2828             : 
    2829         132 :         if (!zend_hash_quick_exists(target, key->arKey, key->nKeyLength, key->h)) {
    2830         406 :                 SEPARATE_ZVAL_TO_MAKE_IS_REF(p);
    2831         109 :                 if (zend_hash_quick_add(target, key->arKey, key->nKeyLength, key->h, p, sizeof(zval*), NULL) == SUCCESS) {
    2832         109 :                         Z_ADDREF_PP(p);
    2833             :                 }
    2834             :         }
    2835         132 :         return ZEND_HASH_APPLY_KEEP;
    2836             : }
    2837             : /* }}} */
    2838             : 
    2839             : #define zval_property_ctor(parent_ce, ce) \
    2840             :         ((copy_ctor_func_t) (((parent_ce)->type != (ce)->type) ? zval_shared_property_ctor : zval_add_ref))
    2841             : 
    2842     1239978 : ZEND_API void zend_do_inheritance(zend_class_entry *ce, zend_class_entry *parent_ce TSRMLS_DC) /* {{{ */
    2843             : {
    2844     1239978 :         if ((ce->ce_flags & ZEND_ACC_INTERFACE)
    2845           0 :                 && !(parent_ce->ce_flags & ZEND_ACC_INTERFACE)) {
    2846           0 :                 zend_error(E_COMPILE_ERROR, "Interface %s may not inherit from class (%s)", ce->name, parent_ce->name);
    2847             :         }
    2848     1239978 :         if (parent_ce->ce_flags & ZEND_ACC_FINAL_CLASS) {
    2849           1 :                 zend_error(E_COMPILE_ERROR, "Class %s may not inherit from final class (%s)", ce->name, parent_ce->name);
    2850             :         }
    2851             : 
    2852     1239977 :         ce->parent = parent_ce;
    2853             :         /* Copy serialize/unserialize callbacks */
    2854     1239977 :         if (!ce->serialize) {
    2855     1239977 :                 ce->serialize   = parent_ce->serialize;
    2856             :         }
    2857     1239977 :         if (!ce->unserialize) {
    2858     1239977 :                 ce->unserialize = parent_ce->unserialize;
    2859             :         }
    2860             : 
    2861             :         /* Inherit interfaces */
    2862     1239977 :         zend_do_inherit_interfaces(ce, parent_ce TSRMLS_CC);
    2863             : 
    2864             :         /* Inherit properties */
    2865     1239977 :         zend_hash_merge(&ce->default_properties, &parent_ce->default_properties, zval_property_ctor(parent_ce, ce), NULL, sizeof(zval *), 0);
    2866     1239977 :         if (parent_ce->type != ce->type) {
    2867             :                 /* User class extends internal class */
    2868        1303 :                 zend_update_class_constants(parent_ce  TSRMLS_CC);
    2869        1303 :                 zend_hash_apply_with_arguments(CE_STATIC_MEMBERS(parent_ce) TSRMLS_CC, (apply_func_args_t)inherit_static_prop, 1, &ce->default_static_members);
    2870             :         } else {
    2871     1238674 :                 zend_hash_apply_with_arguments(&parent_ce->default_static_members TSRMLS_CC, (apply_func_args_t)inherit_static_prop, 1, &ce->default_static_members);
    2872             :         }
    2873     1239977 :         zend_hash_merge_ex(&ce->properties_info, &parent_ce->properties_info, (copy_ctor_func_t) (ce->type & ZEND_INTERNAL_CLASS ? zend_duplicate_property_info_internal : zend_duplicate_property_info), sizeof(zend_property_info), (merge_checker_func_t) do_inherit_property_access_check, ce);
    2874             : 
    2875     1239958 :         zend_hash_merge(&ce->constants_table, &parent_ce->constants_table, zval_property_ctor(parent_ce, ce), NULL, sizeof(zval *), 0);
    2876     1239958 :         zend_hash_merge_ex(&ce->function_table, &parent_ce->function_table, (copy_ctor_func_t) do_inherit_method, sizeof(zend_function), (merge_checker_func_t) do_inherit_method_check, ce);
    2877     1239943 :         do_inherit_parent_constructor(ce);
    2878             : 
    2879     1278623 :         if (ce->ce_flags & ZEND_ACC_IMPLICIT_ABSTRACT_CLASS && ce->type == ZEND_INTERNAL_CLASS) {
    2880       38682 :                 ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
    2881     1201259 :         } else if (!(ce->ce_flags & ZEND_ACC_IMPLEMENT_INTERFACES)) {
    2882             :                 /* The verification will be done in runtime by ZEND_VERIFY_ABSTRACT_CLASS */
    2883     1201207 :                 zend_verify_abstract_class(ce TSRMLS_CC);
    2884             :         }
    2885     1239940 : }
    2886             : /* }}} */
    2887             : 
    2888          21 : static zend_bool do_inherit_constant_check(HashTable *child_constants_table, const zval **parent_constant, const zend_hash_key *hash_key, const zend_class_entry *iface) /* {{{ */
    2889             : {
    2890             :         zval **old_constant;
    2891             : 
    2892          21 :         if (zend_hash_quick_find(child_constants_table, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void**)&old_constant) == SUCCESS) {
    2893           9 :                 if (*old_constant != *parent_constant) {
    2894           6 :                         zend_error(E_COMPILE_ERROR, "Cannot inherit previously-inherited or override constant %s from interface %s", hash_key->arKey, iface->name);
    2895             :                 }
    2896           3 :                 return 0;
    2897             :         }
    2898          12 :         return 1;
    2899             : }
    2900             : /* }}} */
    2901             : 
    2902           4 : static int do_interface_constant_check(zval **val TSRMLS_DC, int num_args, va_list args, const zend_hash_key *key) /* {{{ */
    2903             : {
    2904           4 :         zend_class_entry **iface = va_arg(args, zend_class_entry**);
    2905             : 
    2906           4 :         do_inherit_constant_check(&(*iface)->constants_table, (const zval **) val, key, *iface);
    2907             : 
    2908           3 :         return ZEND_HASH_APPLY_KEEP;
    2909             : }
    2910             : /* }}} */
    2911             : 
    2912     1160788 : ZEND_API void zend_do_implement_interface(zend_class_entry *ce, zend_class_entry *iface TSRMLS_DC) /* {{{ */
    2913             : {
    2914     1160788 :         zend_uint i, ignore = 0;
    2915     1160788 :         zend_uint current_iface_num = ce->num_interfaces;
    2916     1160788 :         zend_uint parent_iface_num  = ce->parent ? ce->parent->num_interfaces : 0;
    2917             : 
    2918     3249730 :         for (i = 0; i < ce->num_interfaces; i++) {
    2919     2088945 :                 if (ce->interfaces[i] == NULL) {
    2920           0 :                         memmove(ce->interfaces + i, ce->interfaces + i + 1, sizeof(zend_class_entry*) * (--ce->num_interfaces - i));
    2921           0 :                         i--;
    2922     2088945 :                 } else if (ce->interfaces[i] == iface) {
    2923           8 :                         if (i < parent_iface_num) {
    2924           5 :                                 ignore = 1;
    2925             :                         } else {
    2926           3 :                                 zend_error(E_COMPILE_ERROR, "Class %s cannot implement previously implemented interface %s", ce->name, iface->name);
    2927             :                         }
    2928             :                 }
    2929             :         }
    2930     1160785 :         if (ignore) {
    2931             :                 /* Check for attempt to redeclare interface constants */
    2932           5 :                 zend_hash_apply_with_arguments(&ce->constants_table TSRMLS_CC, (apply_func_args_t) do_interface_constant_check, 1, &iface);
    2933             :         } else {
    2934     1160780 :                 if (ce->num_interfaces >= current_iface_num) {
    2935     1160780 :                         if (ce->type == ZEND_INTERNAL_CLASS) {
    2936     1160460 :                                 ce->interfaces = (zend_class_entry **) realloc(ce->interfaces, sizeof(zend_class_entry *) * (++current_iface_num));
    2937             :                         } else {
    2938         320 :                                 ce->interfaces = (zend_class_entry **) erealloc(ce->interfaces, sizeof(zend_class_entry *) * (++current_iface_num));
    2939             :                         }
    2940             :                 }
    2941     1160780 :                 ce->interfaces[ce->num_interfaces++] = iface;
    2942             :         
    2943     1160780 :                 zend_hash_merge_ex(&ce->constants_table, &iface->constants_table, (copy_ctor_func_t) zval_add_ref, sizeof(zval *), (merge_checker_func_t) do_inherit_constant_check, iface);
    2944     1160775 :                 zend_hash_merge_ex(&ce->function_table, &iface->function_table, (copy_ctor_func_t) do_inherit_method, sizeof(zend_function), (merge_checker_func_t) do_inherit_method_check, ce);
    2945             :         
    2946     1160772 :                 do_implement_interface(ce, iface TSRMLS_CC);
    2947     1160768 :                 zend_do_inherit_interfaces(ce, iface TSRMLS_CC);
    2948             :         }
    2949     1160772 : }
    2950             : /* }}} */
    2951             : 
    2952       17888 : ZEND_API int do_bind_function(zend_op *opline, HashTable *function_table, zend_bool compile_time) /* {{{ */
    2953             : {
    2954             :         zend_function *function;
    2955             : 
    2956       17888 :         zend_hash_find(function_table, opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len, (void *) &function);
    2957       17888 :         if (zend_hash_add(function_table, opline->op2.u.constant.value.str.val, opline->op2.u.constant.value.str.len+1, function, sizeof(zend_function), NULL)==FAILURE) {
    2958           0 :                 int error_level = compile_time ? E_COMPILE_ERROR : E_ERROR;
    2959             :                 zend_function *old_function;
    2960             : 
    2961           0 :                 if (zend_hash_find(function_table, opline->op2.u.constant.value.str.val, opline->op2.u.constant.value.str.len+1, (void *) &old_function)==SUCCESS
    2962           0 :                         && old_function->type == ZEND_USER_FUNCTION
    2963           0 :                         && old_function->op_array.last > 0) {
    2964           0 :                         zend_error(error_level, "Cannot redeclare %s() (previously declared in %s:%d)",
    2965           0 :                                                 function->common.function_name,
    2966           0 :                                                 old_function->op_array.filename,
    2967           0 :                                                 old_function->op_array.opcodes[0].lineno);
    2968             :                 } else {
    2969           0 :                         zend_error(error_level, "Cannot redeclare %s()", function->common.function_name);
    2970             :                 }
    2971           0 :                 return FAILURE;
    2972             :         } else {
    2973       17888 :                 (*function->op_array.refcount)++;
    2974       17888 :                 function->op_array.static_variables = NULL; /* NULL out the unbound function */
    2975       17888 :                 return SUCCESS;
    2976             :         }
    2977             : }
    2978             : /* }}} */
    2979             : 
    2980        4459 : ZEND_API zend_class_entry *do_bind_class(const zend_op *opline, HashTable *class_table, zend_bool compile_time TSRMLS_DC) /* {{{ */
    2981             : {
    2982             :         zend_class_entry *ce, **pce;
    2983             : 
    2984        4459 :         if (zend_hash_find(class_table, opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len, (void **) &pce)==FAILURE) {
    2985           0 :                 zend_error(E_COMPILE_ERROR, "Internal Zend error - Missing class information for %s", opline->op1.u.constant.value.str.val);
    2986           0 :                 return NULL;
    2987             :         } else {
    2988        4459 :                 ce = *pce;
    2989             :         }
    2990        4459 :         ce->refcount++;
    2991        4459 :         if (zend_hash_add(class_table, opline->op2.u.constant.value.str.val, opline->op2.u.constant.value.str.len+1, &ce, sizeof(zend_class_entry *), NULL)==FAILURE) {
    2992           4 :                 ce->refcount--;
    2993           4 :                 if (!compile_time) {
    2994             :                         /* If we're in compile time, in practice, it's quite possible
    2995             :                          * that we'll never reach this class declaration at runtime,
    2996             :                          * so we shut up about it.  This allows the if (!defined('FOO')) { return; }
    2997             :                          * approach to work.
    2998             :                          */
    2999           2 :                         zend_error(E_COMPILE_ERROR, "Cannot redeclare class %s", ce->name);
    3000             :                 }
    3001           2 :                 return NULL;
    3002             :         } else {
    3003        4455 :                 if (!(ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_IMPLEMENT_INTERFACES))) {
    3004        4089 :                         zend_verify_abstract_class(ce TSRMLS_CC);
    3005             :                 }
    3006        4455 :                 return ce;
    3007             :         }
    3008             : }
    3009             : /* }}} */
    3010             : 
    3011        2155 : ZEND_API zend_class_entry *do_bind_inherited_class(const zend_op *opline, HashTable *class_table, zend_class_entry *parent_ce, zend_bool compile_time TSRMLS_DC) /* {{{ */
    3012             : {
    3013             :         zend_class_entry *ce, **pce;
    3014             :         int found_ce;
    3015             : 
    3016        2155 :         found_ce = zend_hash_find(class_table, opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len, (void **) &pce);
    3017             : 
    3018        2155 :         if (found_ce == FAILURE) {
    3019           0 :                 if (!compile_time) {
    3020             :                         /* If we're in compile time, in practice, it's quite possible
    3021             :                          * that we'll never reach this class declaration at runtime,
    3022             :                          * so we shut up about it.  This allows the if (!defined('FOO')) { return; }
    3023             :                          * approach to work.
    3024             :                          */
    3025           0 :                         zend_error(E_COMPILE_ERROR, "Cannot redeclare class %s", opline->op2.u.constant.value.str.val);
    3026             :                 }
    3027           0 :                 return NULL;
    3028             :         } else {
    3029        2155 :                 ce = *pce;
    3030             :         }
    3031             : 
    3032        2155 :         if (parent_ce->ce_flags & ZEND_ACC_INTERFACE) {
    3033           1 :                 zend_error(E_COMPILE_ERROR, "Class %s cannot extend from interface %s", ce->name, parent_ce->name);
    3034             :         }
    3035             : 
    3036        2154 :         zend_do_inheritance(ce, parent_ce TSRMLS_CC);
    3037             : 
    3038        2116 :         ce->refcount++;
    3039             : 
    3040             :         /* Register the derived class */
    3041        2116 :         if (zend_hash_add(class_table, opline->op2.u.constant.value.str.val, opline->op2.u.constant.value.str.len+1, pce, sizeof(zend_class_entry *), NULL)==FAILURE) {
    3042           0 :                 zend_error(E_COMPILE_ERROR, "Cannot redeclare class %s", ce->name);
    3043             :         }
    3044        2116 :         return ce;
    3045             : }
    3046             : /* }}} */
    3047             : 
    3048       19261 : void zend_do_early_binding(TSRMLS_D) /* {{{ */
    3049             : {
    3050       19261 :         zend_op *opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
    3051             :         HashTable *table;
    3052             : 
    3053       38522 :         while (opline->opcode == ZEND_TICKS && opline > CG(active_op_array)->opcodes) {
    3054           0 :                 opline--;
    3055             :         }
    3056             : 
    3057       19261 :         switch (opline->opcode) {
    3058             :                 case ZEND_DECLARE_FUNCTION:
    3059       13545 :                         if (do_bind_function(opline, CG(function_table), 1) == FAILURE) {
    3060           0 :                                 return;
    3061             :                         }
    3062       13545 :                         table = CG(function_table);
    3063       13545 :                         break;
    3064             :                 case ZEND_DECLARE_CLASS:
    3065        4208 :                         if (do_bind_class(opline, CG(class_table), 1 TSRMLS_CC) == NULL) {
    3066           2 :                                 return;
    3067             :                         }
    3068        4206 :                         table = CG(class_table);
    3069        4206 :                         break;
    3070             :                 case ZEND_DECLARE_INHERITED_CLASS:
    3071             :                         {
    3072        1216 :                                 zend_op *fetch_class_opline = opline-1;
    3073        1216 :                                 zval *parent_name = &fetch_class_opline->op2.u.constant;
    3074             :                                 zend_class_entry **pce;
    3075             : 
    3076        2168 :                                 if ((zend_lookup_class(Z_STRVAL_P(parent_name), Z_STRLEN_P(parent_name), &pce TSRMLS_CC) == FAILURE) ||
    3077         952 :                                                 ((CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_CLASSES) &&
    3078           0 :                                                 ((*pce)->type == ZEND_INTERNAL_CLASS))) {
    3079         264 :                                         if (CG(compiler_options) & ZEND_COMPILE_DELAYED_BINDING) {
    3080           0 :                                                 zend_uint *opline_num = &CG(active_op_array)->early_binding;
    3081             : 
    3082           0 :                                                 while (*opline_num != -1) {
    3083           0 :                                                         opline_num = &CG(active_op_array)->opcodes[*opline_num].result.u.opline_num;
    3084             :                                                 }
    3085           0 :                                                 *opline_num = opline - CG(active_op_array)->opcodes;
    3086           0 :                                                 opline->opcode = ZEND_DECLARE_INHERITED_CLASS_DELAYED;
    3087           0 :                                                 opline->result.op_type = IS_UNUSED;
    3088           0 :                                                 opline->result.u.opline_num = -1;
    3089             :                                         }
    3090         264 :                                         return;
    3091             :                                 }
    3092         952 :                                 if (do_bind_inherited_class(opline, CG(class_table), *pce, 1 TSRMLS_CC) == NULL) {
    3093           0 :                                         return;
    3094             :                                 }
    3095             :                                 /* clear unnecessary ZEND_FETCH_CLASS opcode */
    3096         915 :                                 zval_dtor(&fetch_class_opline->op2.u.constant);
    3097         915 :                                 MAKE_NOP(fetch_class_opline);
    3098             : 
    3099         915 :                                 table = CG(class_table);
    3100         915 :                                 break;
    3101             :                         }
    3102             :                 case ZEND_VERIFY_ABSTRACT_CLASS:
    3103             :                 case ZEND_ADD_INTERFACE:
    3104             :                         /* We currently don't early-bind classes that implement interfaces */
    3105         292 :                         return;
    3106             :                 default:
    3107           0 :                         zend_error(E_COMPILE_ERROR, "Invalid binding type");
    3108           0 :                         return;
    3109             :         }
    3110             : 
    3111       18666 :         zend_hash_del(table, opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len);
    3112       18666 :         zval_dtor(&opline->op1.u.constant);
    3113       18666 :         zval_dtor(&opline->op2.u.constant);
    3114       18666 :         MAKE_NOP(opline);
    3115             : }
    3116             : /* }}} */
    3117             : 
    3118           0 : ZEND_API void zend_do_delayed_early_binding(const zend_op_array *op_array TSRMLS_DC) /* {{{ */
    3119             : {
    3120           0 :         if (op_array->early_binding != -1) {
    3121           0 :                 zend_bool orig_in_compilation = CG(in_compilation);
    3122           0 :                 zend_uint opline_num = op_array->early_binding;
    3123             :                 zend_class_entry **pce;
    3124             : 
    3125           0 :                 CG(in_compilation) = 1;
    3126           0 :                 while (opline_num != -1) {
    3127           0 :                         if (zend_lookup_class(Z_STRVAL(op_array->opcodes[opline_num-1].op2.u.constant), Z_STRLEN(op_array->opcodes[opline_num-1].op2.u.constant), &pce TSRMLS_CC) == SUCCESS) {
    3128           0 :                                 do_bind_inherited_class(&op_array->opcodes[opline_num], EG(class_table), *pce, 1 TSRMLS_CC);
    3129             :                         }
    3130           0 :                         opline_num = op_array->opcodes[opline_num].result.u.opline_num;
    3131             :                 }
    3132           0 :                 CG(in_compilation) = orig_in_compilation;
    3133             :         }
    3134           0 : }
    3135             : /* }}} */
    3136             : 
    3137       10383 : void zend_do_boolean_or_begin(znode *expr1, znode *op_token TSRMLS_DC) /* {{{ */
    3138             : {
    3139       10383 :         int next_op_number = get_next_op_number(CG(active_op_array));
    3140       10383 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3141             : 
    3142       10383 :         opline->opcode = ZEND_JMPNZ_EX;
    3143       10383 :         if (expr1->op_type == IS_TMP_VAR) {
    3144        9587 :                 opline->result = *expr1;
    3145             :         } else {
    3146         796 :                 opline->result.u.var = get_temporary_variable(CG(active_op_array));
    3147         796 :                 opline->result.op_type = IS_TMP_VAR;
    3148             :         }
    3149       10383 :         opline->op1 = *expr1;
    3150       10383 :         SET_UNUSED(opline->op2);
    3151             : 
    3152       10383 :         op_token->u.opline_num = next_op_number;
    3153             : 
    3154       10383 :         *expr1 = opline->result;
    3155       10383 : }
    3156             : /* }}} */
    3157             : 
    3158       10383 : void zend_do_boolean_or_end(znode *result, const znode *expr1, const znode *expr2, znode *op_token TSRMLS_DC) /* {{{ */
    3159             : {
    3160       10383 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3161             : 
    3162       10383 :         *result = *expr1; /* we saved the original result in expr1 */
    3163       10383 :         opline->opcode = ZEND_BOOL;
    3164       10383 :         opline->result = *result;
    3165       10383 :         opline->op1 = *expr2;
    3166       10383 :         SET_UNUSED(opline->op2);
    3167             : 
    3168       10383 :         CG(active_op_array)->opcodes[op_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array));
    3169       10383 : }
    3170             : /* }}} */
    3171             : 
    3172        6823 : void zend_do_boolean_and_begin(znode *expr1, znode *op_token TSRMLS_DC) /* {{{ */
    3173             : {
    3174        6823 :         int next_op_number = get_next_op_number(CG(active_op_array));
    3175        6823 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3176             : 
    3177        6823 :         opline->opcode = ZEND_JMPZ_EX;
    3178        6823 :         if (expr1->op_type == IS_TMP_VAR) {
    3179        4219 :                 opline->result = *expr1;
    3180             :         } else {
    3181        2604 :                 opline->result.u.var = get_temporary_variable(CG(active_op_array));
    3182        2604 :                 opline->result.op_type = IS_TMP_VAR;
    3183             :         }
    3184        6823 :         opline->op1 = *expr1;
    3185        6823 :         SET_UNUSED(opline->op2);
    3186             : 
    3187        6823 :         op_token->u.opline_num = next_op_number;
    3188             : 
    3189        6823 :         *expr1 = opline->result;
    3190        6823 : }
    3191             : /* }}} */
    3192             : 
    3193        6823 : void zend_do_boolean_and_end(znode *result, const znode *expr1, const znode *expr2, const znode *op_token TSRMLS_DC) /* {{{ */
    3194             : {
    3195        6823 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3196             : 
    3197        6823 :         *result = *expr1; /* we saved the original result in expr1 */
    3198        6823 :         opline->opcode = ZEND_BOOL;
    3199        6823 :         opline->result = *result;
    3200        6823 :         opline->op1 = *expr2;
    3201        6823 :         SET_UNUSED(opline->op2);
    3202             : 
    3203        6823 :         CG(active_op_array)->opcodes[op_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array));
    3204        6823 : }
    3205             : /* }}} */
    3206             : 
    3207         272 : void zend_do_do_while_begin(TSRMLS_D) /* {{{ */
    3208             : {
    3209         272 :         do_begin_loop(TSRMLS_C);
    3210         272 :         INC_BPC(CG(active_op_array));
    3211         272 : }
    3212             : /* }}} */
    3213             : 
    3214         272 : void zend_do_do_while_end(const znode *do_token, const znode *expr_open_bracket, const znode *expr TSRMLS_DC) /* {{{ */
    3215             : {
    3216         272 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3217             : 
    3218         272 :         opline->opcode = ZEND_JMPNZ;
    3219         272 :         opline->op1 = *expr;
    3220         272 :         opline->op2.u.opline_num = do_token->u.opline_num;
    3221         272 :         SET_UNUSED(opline->op2);
    3222             : 
    3223         272 :         do_end_loop(expr_open_bracket->u.opline_num, 0 TSRMLS_CC);
    3224             : 
    3225         272 :         DEC_BPC(CG(active_op_array));
    3226         272 : }
    3227             : /* }}} */
    3228             : 
    3229        1898 : void zend_do_brk_cont(zend_uchar op, const znode *expr TSRMLS_DC) /* {{{ */
    3230             : {
    3231        1898 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3232             : 
    3233        1898 :         opline->opcode = op;
    3234        1898 :         opline->op1.u.opline_num = CG(active_op_array)->current_brk_cont;
    3235        1898 :         SET_UNUSED(opline->op1);
    3236        1898 :         if (expr) {
    3237          11 :                 opline->op2 = *expr;
    3238             :         } else {
    3239        1887 :                 Z_TYPE(opline->op2.u.constant) = IS_LONG;
    3240        1887 :                 Z_LVAL(opline->op2.u.constant) = 1;
    3241        1887 :                 INIT_PZVAL(&opline->op2.u.constant);
    3242        1887 :                 opline->op2.op_type = IS_CONST;
    3243             :         }
    3244        1898 : }
    3245             : /* }}} */
    3246             : 
    3247         444 : void zend_do_switch_cond(const znode *cond TSRMLS_DC) /* {{{ */
    3248             : {
    3249             :         zend_switch_entry switch_entry;
    3250             : 
    3251         444 :         switch_entry.cond = *cond;
    3252         444 :         switch_entry.default_case = -1;
    3253         444 :         switch_entry.control_var = -1;
    3254         444 :         zend_stack_push(&CG(switch_cond_stack), (void *) &switch_entry, sizeof(switch_entry));
    3255             : 
    3256         444 :         do_begin_loop(TSRMLS_C);
    3257             : 
    3258         444 :         INC_BPC(CG(active_op_array));
    3259         444 : }
    3260             : /* }}} */
    3261             : 
    3262         444 : void zend_do_switch_end(const znode *case_list TSRMLS_DC) /* {{{ */
    3263             : {
    3264             :         zend_op *opline;
    3265             :         zend_switch_entry *switch_entry_ptr;
    3266             : 
    3267         444 :         zend_stack_top(&CG(switch_cond_stack), (void **) &switch_entry_ptr);
    3268             : 
    3269             :         /* add code to jmp to default case */
    3270         444 :         if (switch_entry_ptr->default_case != -1) {
    3271         265 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3272         265 :                 opline->opcode = ZEND_JMP;
    3273         265 :                 SET_UNUSED(opline->op1);
    3274         265 :                 SET_UNUSED(opline->op2);
    3275         265 :                 opline->op1.u.opline_num = switch_entry_ptr->default_case;
    3276             :         }
    3277             : 
    3278         444 :         if (case_list->op_type != IS_UNUSED) { /* non-empty switch */
    3279         444 :                 int next_op_number = get_next_op_number(CG(active_op_array));
    3280             : 
    3281         444 :                 CG(active_op_array)->opcodes[case_list->u.opline_num].op1.u.opline_num = next_op_number;
    3282             :         }
    3283             : 
    3284             :         /* remember break/continue loop information */
    3285         444 :         CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].cont = CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].brk = get_next_op_number(CG(active_op_array));
    3286         444 :         CG(active_op_array)->current_brk_cont = CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].parent;
    3287             : 
    3288         444 :         if (switch_entry_ptr->cond.op_type==IS_VAR || switch_entry_ptr->cond.op_type==IS_TMP_VAR) {
    3289             :                 /* emit free for the switch condition*/
    3290          96 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3291          96 :                 opline->opcode = (switch_entry_ptr->cond.op_type == IS_TMP_VAR) ? ZEND_FREE : ZEND_SWITCH_FREE;
    3292          96 :                 opline->op1 = switch_entry_ptr->cond;
    3293          96 :                 SET_UNUSED(opline->op2);
    3294             :         }
    3295         444 :         if (switch_entry_ptr->cond.op_type == IS_CONST) {
    3296           7 :                 zval_dtor(&switch_entry_ptr->cond.u.constant);
    3297             :         }
    3298             : 
    3299         444 :         zend_stack_del_top(&CG(switch_cond_stack));
    3300             : 
    3301         444 :         DEC_BPC(CG(active_op_array));
    3302         444 : }
    3303             : /* }}} */
    3304             : 
    3305        1486 : void zend_do_case_before_statement(const znode *case_list, znode *case_token, const znode *case_expr TSRMLS_DC) /* {{{ */
    3306             : {
    3307        1486 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3308             :         int next_op_number;
    3309             :         zend_switch_entry *switch_entry_ptr;
    3310             :         znode result;
    3311             : 
    3312        1486 :         zend_stack_top(&CG(switch_cond_stack), (void **) &switch_entry_ptr);
    3313             : 
    3314        1486 :         if (switch_entry_ptr->control_var == -1) {
    3315         443 :                 switch_entry_ptr->control_var = get_temporary_variable(CG(active_op_array));
    3316             :         }
    3317        1486 :         opline->opcode = ZEND_CASE;
    3318        1486 :         opline->result.u.var = switch_entry_ptr->control_var;
    3319        1486 :         opline->result.op_type = IS_TMP_VAR;
    3320        1486 :         opline->op1 = switch_entry_ptr->cond;
    3321        1486 :         opline->op2 = *case_expr;
    3322        1486 :         if (opline->op1.op_type == IS_CONST) {
    3323          14 :                 zval_copy_ctor(&opline->op1.u.constant);
    3324             :         }
    3325        1486 :         result = opline->result;
    3326             : 
    3327        1486 :         next_op_number = get_next_op_number(CG(active_op_array));
    3328        1486 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3329        1486 :         opline->opcode = ZEND_JMPZ;
    3330        1486 :         opline->op1 = result;
    3331        1486 :         SET_UNUSED(opline->op2);
    3332        1486 :         case_token->u.opline_num = next_op_number;
    3333             : 
    3334        1486 :         if (case_list->op_type==IS_UNUSED) {
    3335         300 :                 return;
    3336             :         }
    3337        1186 :         next_op_number = get_next_op_number(CG(active_op_array));
    3338        1186 :         CG(active_op_array)->opcodes[case_list->u.opline_num].op1.u.opline_num = next_op_number;
    3339             : }
    3340             : /* }}} */
    3341             : 
    3342        1753 : void zend_do_case_after_statement(znode *result, const znode *case_token TSRMLS_DC) /* {{{ */
    3343             : {
    3344        1753 :         int next_op_number = get_next_op_number(CG(active_op_array));
    3345        1753 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3346             : 
    3347        1753 :         opline->opcode = ZEND_JMP;
    3348        1753 :         SET_UNUSED(opline->op1);
    3349        1753 :         SET_UNUSED(opline->op2);
    3350        1753 :         result->u.opline_num = next_op_number;
    3351             : 
    3352        1753 :         switch (CG(active_op_array)->opcodes[case_token->u.opline_num].opcode) {
    3353             :                 case ZEND_JMP:
    3354         267 :                         CG(active_op_array)->opcodes[case_token->u.opline_num].op1.u.opline_num = get_next_op_number(CG(active_op_array));
    3355         267 :                         break;
    3356             :                 case ZEND_JMPZ:
    3357        1486 :                         CG(active_op_array)->opcodes[case_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array));
    3358             :                         break;
    3359             :         }
    3360        1753 : }
    3361             : /* }}} */
    3362             : 
    3363         267 : void zend_do_default_before_statement(const znode *case_list, znode *default_token TSRMLS_DC) /* {{{ */
    3364             : {
    3365         267 :         int next_op_number = get_next_op_number(CG(active_op_array));
    3366         267 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3367             :         zend_switch_entry *switch_entry_ptr;
    3368             : 
    3369         267 :         zend_stack_top(&CG(switch_cond_stack), (void **) &switch_entry_ptr);
    3370             : 
    3371         267 :         opline->opcode = ZEND_JMP;
    3372         267 :         SET_UNUSED(opline->op1);
    3373         267 :         SET_UNUSED(opline->op2);
    3374         267 :         default_token->u.opline_num = next_op_number;
    3375             : 
    3376         267 :         next_op_number = get_next_op_number(CG(active_op_array));
    3377         267 :         switch_entry_ptr->default_case = next_op_number;
    3378             : 
    3379         267 :         if (case_list->op_type==IS_UNUSED) {
    3380         144 :                 return;
    3381             :         }
    3382         123 :         CG(active_op_array)->opcodes[case_list->u.opline_num].op1.u.opline_num = next_op_number;
    3383             : }
    3384             : /* }}} */
    3385             : 
    3386        6690 : void zend_do_begin_class_declaration(const znode *class_token, znode *class_name, const znode *parent_class_name TSRMLS_DC) /* {{{ */
    3387             : {
    3388             :         zend_op *opline;
    3389        6690 :         int doing_inheritance = 0;
    3390             :         zend_class_entry *new_class_entry;
    3391             :         char *lcname;
    3392        6690 :         int error = 0;
    3393             :         zval **ns_name;
    3394             : 
    3395        6690 :         if (CG(active_class_entry)) {
    3396           1 :                 zend_error(E_COMPILE_ERROR, "Class declarations may not be nested");
    3397           0 :                 return;
    3398             :         }
    3399             : 
    3400        6689 :         lcname = zend_str_tolower_dup(class_name->u.constant.value.str.val, class_name->u.constant.value.str.len);
    3401             : 
    3402        6689 :         if (!(strcmp(lcname, "self") && strcmp(lcname, "parent"))) {
    3403           2 :                 efree(lcname);
    3404           2 :                 zend_error(E_COMPILE_ERROR, "Cannot use '%s' as class name as it is reserved", class_name->u.constant.value.str.val);
    3405             :         }
    3406             : 
    3407             :         /* Class name must not conflict with import names */
    3408        6709 :         if (CG(current_import) &&
    3409          22 :                         zend_hash_find(CG(current_import), lcname, Z_STRLEN(class_name->u.constant)+1, (void**)&ns_name) == SUCCESS) {
    3410           2 :                 error = 1;
    3411             :         }
    3412             : 
    3413        6687 :         if (CG(current_namespace)) {
    3414             :                 /* Prefix class name with name of current namespace */
    3415             :                 znode tmp;
    3416             : 
    3417          90 :                 tmp.op_type = IS_CONST;
    3418          90 :                 tmp.u.constant = *CG(current_namespace);
    3419          90 :                 zval_copy_ctor(&tmp.u.constant);
    3420          90 :                 zend_do_build_namespace_name(&tmp, &tmp, class_name TSRMLS_CC);
    3421          90 :                 *class_name = tmp;
    3422          90 :                 efree(lcname);
    3423          90 :                 lcname = zend_str_tolower_dup(Z_STRVAL(class_name->u.constant), Z_STRLEN(class_name->u.constant));
    3424             :         }
    3425             : 
    3426        6687 :         if (error) {
    3427           2 :                 char *tmp = zend_str_tolower_dup(Z_STRVAL_PP(ns_name), Z_STRLEN_PP(ns_name));
    3428             : 
    3429           4 :                 if (Z_STRLEN_PP(ns_name) != Z_STRLEN(class_name->u.constant) ||
    3430           2 :                         memcmp(tmp, lcname, Z_STRLEN(class_name->u.constant))) {
    3431           1 :                         zend_error(E_COMPILE_ERROR, "Cannot declare class %s because the name is already in use", Z_STRVAL(class_name->u.constant));
    3432             :                 }
    3433           1 :                 efree(tmp);
    3434             :         }
    3435             : 
    3436        6686 :         new_class_entry = emalloc(sizeof(zend_class_entry));
    3437        6686 :         new_class_entry->type = ZEND_USER_CLASS;
    3438        6686 :         new_class_entry->name = class_name->u.constant.value.str.val;
    3439        6686 :         new_class_entry->name_length = class_name->u.constant.value.str.len;
    3440             : 
    3441        6686 :         zend_initialize_class_data(new_class_entry, 1 TSRMLS_CC);
    3442        6686 :         new_class_entry->filename = zend_get_compiled_filename(TSRMLS_C);
    3443        6686 :         new_class_entry->line_start = class_token->u.opline_num;
    3444        6686 :         new_class_entry->ce_flags |= class_token->u.EA.type;
    3445             : 
    3446        6686 :         if (parent_class_name && parent_class_name->op_type != IS_UNUSED) {
    3447        2161 :                 switch (parent_class_name->u.EA.type) {
    3448             :                         case ZEND_FETCH_CLASS_SELF:
    3449           1 :                                 zend_error(E_COMPILE_ERROR, "Cannot use 'self' as class name as it is reserved");
    3450           0 :                                 break;
    3451             :                         case ZEND_FETCH_CLASS_PARENT:
    3452           1 :                                 zend_error(E_COMPILE_ERROR, "Cannot use 'parent' as class name as it is reserved");
    3453           0 :                                 break;
    3454             :                         case ZEND_FETCH_CLASS_STATIC:
    3455           0 :                                 zend_error(E_COMPILE_ERROR, "Cannot use 'static' as class name as it is reserved");
    3456             :                                 break;
    3457             :                         default:
    3458             :                                 break;
    3459             :                 }
    3460        2159 :                 doing_inheritance = 1;
    3461             :         }
    3462             : 
    3463        6684 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3464        6684 :         opline->op1.op_type = IS_CONST;
    3465        6684 :         build_runtime_defined_function_key(&opline->op1.u.constant, lcname, new_class_entry->name_length TSRMLS_CC);
    3466             :         
    3467        6684 :         opline->op2.op_type = IS_CONST;
    3468        6684 :         opline->op2.u.constant.type = IS_STRING;
    3469        6684 :         Z_SET_REFCOUNT(opline->op2.u.constant, 1);
    3470             : 
    3471        6684 :         if (doing_inheritance) {
    3472        2159 :                 opline->extended_value = parent_class_name->u.var;
    3473        2159 :                 opline->opcode = ZEND_DECLARE_INHERITED_CLASS;
    3474             :         } else {
    3475        4525 :                 opline->opcode = ZEND_DECLARE_CLASS;
    3476             :         }
    3477             : 
    3478        6684 :         opline->op2.u.constant.value.str.val = lcname;
    3479        6684 :         opline->op2.u.constant.value.str.len = new_class_entry->name_length;
    3480             :         
    3481        6684 :         zend_hash_update(CG(class_table), opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len, &new_class_entry, sizeof(zend_class_entry *), NULL);
    3482        6684 :         CG(active_class_entry) = new_class_entry;
    3483             : 
    3484        6684 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    3485        6684 :         opline->result.op_type = IS_VAR;
    3486        6684 :         CG(implementing_class) = opline->result;
    3487             : 
    3488        6684 :         if (CG(doc_comment)) {
    3489          14 :                 CG(active_class_entry)->doc_comment = CG(doc_comment);
    3490          14 :                 CG(active_class_entry)->doc_comment_len = CG(doc_comment_len);
    3491          14 :                 CG(doc_comment) = NULL;
    3492          14 :                 CG(doc_comment_len) = 0;
    3493             :         }
    3494             : }
    3495             : /* }}} */
    3496             : 
    3497         251 : static void do_verify_abstract_class(TSRMLS_D) /* {{{ */
    3498             : {
    3499         251 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3500             : 
    3501         251 :         opline->opcode = ZEND_VERIFY_ABSTRACT_CLASS;
    3502         251 :         opline->op1 = CG(implementing_class);
    3503         251 :         SET_UNUSED(opline->op2);
    3504         251 : }
    3505             : /* }}} */
    3506             : 
    3507        6626 : void zend_do_end_class_declaration(const znode *class_token, const znode *parent_token TSRMLS_DC) /* {{{ */
    3508             : {
    3509        6626 :         zend_class_entry *ce = CG(active_class_entry);
    3510             : 
    3511        6626 :         if (ce->constructor) {
    3512        1768 :                 ce->constructor->common.fn_flags |= ZEND_ACC_CTOR;
    3513        1768 :                 if (ce->constructor->common.fn_flags & ZEND_ACC_STATIC) {
    3514           2 :                         zend_error(E_COMPILE_ERROR, "Constructor %s::%s() cannot be static", ce->name, ce->constructor->common.function_name);
    3515             :                 }
    3516             :         }
    3517        6624 :         if (ce->destructor) {
    3518         145 :                 ce->destructor->common.fn_flags |= ZEND_ACC_DTOR;
    3519         145 :                 if (ce->destructor->common.fn_flags & ZEND_ACC_STATIC) {
    3520           1 :                         zend_error(E_COMPILE_ERROR, "Destructor %s::%s() cannot be static", ce->name, ce->destructor->common.function_name);
    3521             :                 }
    3522             :         }
    3523        6623 :         if (ce->clone) {
    3524          19 :                 ce->clone->common.fn_flags |= ZEND_ACC_CLONE;
    3525          19 :                 if (ce->clone->common.fn_flags & ZEND_ACC_STATIC) {
    3526           1 :                         zend_error(E_COMPILE_ERROR, "Clone method %s::%s() cannot be static", ce->name, ce->clone->common.function_name);
    3527             :                 }
    3528             :         }
    3529             : 
    3530        6622 :         ce->line_end = zend_get_compiled_lineno(TSRMLS_C);
    3531             : 
    3532        6622 :         if (!(ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))
    3533           0 :                 && (parent_token || (ce->num_interfaces > 0))) {
    3534        6393 :                 zend_verify_abstract_class(ce TSRMLS_CC);
    3535        6388 :                 if (ce->num_interfaces) {
    3536         251 :                         do_verify_abstract_class(TSRMLS_C);
    3537             :                 }
    3538             :         }
    3539             :         /* Inherit interfaces; reset number to zero, we need it for above check and
    3540             :          * will restore it during actual implementation. 
    3541             :          * The ZEND_ACC_IMPLEMENT_INTERFACES flag disables double call to
    3542             :          * zend_verify_abstract_class() */
    3543        6617 :         if (ce->num_interfaces > 0) {
    3544         295 :                 ce->interfaces = NULL;
    3545         295 :                 ce->num_interfaces = 0;
    3546         295 :                 ce->ce_flags |= ZEND_ACC_IMPLEMENT_INTERFACES;
    3547             :         }
    3548        6617 :         CG(active_class_entry) = NULL;
    3549        6617 : }
    3550             : /* }}} */
    3551             : 
    3552         337 : void zend_do_implements_interface(znode *interface_name TSRMLS_DC) /* {{{ */
    3553             : {
    3554             :         zend_op *opline;
    3555             : 
    3556         337 :         switch (zend_get_class_fetch_type(Z_STRVAL(interface_name->u.constant), Z_STRLEN(interface_name->u.constant))) {
    3557             :                 case ZEND_FETCH_CLASS_SELF:
    3558             :                 case ZEND_FETCH_CLASS_PARENT:
    3559             :                 case ZEND_FETCH_CLASS_STATIC:
    3560           2 :                         zend_error(E_COMPILE_ERROR, "Cannot use '%s' as interface name as it is reserved", Z_STRVAL(interface_name->u.constant));
    3561             :                         break;
    3562             :                 default:
    3563             :                         break;
    3564             :         }
    3565             : 
    3566         335 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3567         335 :         opline->opcode = ZEND_ADD_INTERFACE;
    3568         335 :         opline->op1 = CG(implementing_class);
    3569         335 :         zend_resolve_class_name(interface_name, &opline->extended_value, 0 TSRMLS_CC);
    3570         335 :         opline->extended_value = (opline->extended_value & ~ZEND_FETCH_CLASS_MASK) | ZEND_FETCH_CLASS_INTERFACE;
    3571         335 :         opline->op2 = *interface_name;
    3572         335 :         CG(active_class_entry)->num_interfaces++;
    3573         335 : }
    3574             : /* }}} */
    3575             : 
    3576      310864 : ZEND_API void zend_mangle_property_name(char **dest, int *dest_length, const char *src1, int src1_length, const char *src2, int src2_length, int internal) /* {{{ */
    3577             : {
    3578             :         char *prop_name;
    3579             :         int prop_name_length;
    3580             : 
    3581      310864 :         prop_name_length = 1 + src1_length + 1 + src2_length;
    3582      310864 :         prop_name = pemalloc(prop_name_length + 1, internal);
    3583      310864 :         prop_name[0] = '\0';
    3584      310864 :         memcpy(prop_name + 1, src1, src1_length+1);
    3585      310864 :         memcpy(prop_name + 1 + src1_length + 1, src2, src2_length+1);
    3586             : 
    3587      310864 :         *dest = prop_name;
    3588      310864 :         *dest_length = prop_name_length;
    3589      310864 : }
    3590             : /* }}} */
    3591             : 
    3592        2097 : static int zend_strnlen(const char* s, int maxlen) /* {{{ */
    3593             : {
    3594        2097 :         int len = 0;
    3595        2097 :         while (*s++ && maxlen--) len++;
    3596        2097 :         return len;
    3597             : }
    3598             : /* }}} */
    3599             : 
    3600        9805 : ZEND_API int zend_unmangle_property_name(char *mangled_property, int len, char **class_name, char **prop_name) /* {{{ */
    3601             : {
    3602             :         int class_name_len;
    3603             : 
    3604        9805 :         *class_name = NULL;
    3605             : 
    3606        9805 :         if (mangled_property[0]!=0) {
    3607        7708 :                 *prop_name = mangled_property;
    3608        7708 :                 return SUCCESS;
    3609             :         }
    3610        2097 :         if (len < 3 || mangled_property[1]==0) {
    3611           0 :                 zend_error(E_NOTICE, "Illegal member variable name");
    3612           0 :                 *prop_name = mangled_property;
    3613           0 :                 return FAILURE;
    3614             :         }
    3615             : 
    3616        2097 :         class_name_len = zend_strnlen(mangled_property+1, --len - 1) + 1;
    3617        2097 :         if (class_name_len >= len || mangled_property[class_name_len]!=0) {
    3618           0 :                 zend_error(E_NOTICE, "Corrupt member variable name");
    3619           0 :                 *prop_name = mangled_property;
    3620           0 :                 return FAILURE;
    3621             :         }
    3622        2097 :         *class_name = mangled_property+1;
    3623        2097 :         *prop_name = (*class_name)+class_name_len;
    3624        2097 :         return SUCCESS;
    3625             : }
    3626             : /* }}} */
    3627             : 
    3628        1944 : void zend_do_declare_property(const znode *var_name, const znode *value, zend_uint access_type TSRMLS_DC) /* {{{ */
    3629             : {
    3630             :         zval *property;
    3631             :         zend_property_info *existing_property_info;
    3632        1944 :         char *comment = NULL;
    3633        1944 :         int comment_len = 0;
    3634             : 
    3635        1944 :         if (CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE) {
    3636           1 :                 zend_error(E_COMPILE_ERROR, "Interfaces may not include member variables");
    3637             :         }
    3638             : 
    3639        1943 :         if (access_type & ZEND_ACC_ABSTRACT) {
    3640           1 :                 zend_error(E_COMPILE_ERROR, "Properties cannot be declared abstract");
    3641             :         }
    3642             : 
    3643        1942 :         if (access_type & ZEND_ACC_FINAL) {
    3644           2 :                 zend_error(E_COMPILE_ERROR, "Cannot declare property %s::$%s final, the final modifier is allowed only for methods and classes",
    3645           1 :                                         CG(active_class_entry)->name, var_name->u.constant.value.str.val);
    3646             :         }
    3647             : 
    3648        1941 :         if (zend_hash_find(&CG(active_class_entry)->properties_info, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, (void **) &existing_property_info)==SUCCESS) {
    3649           1 :                 if (!(existing_property_info->flags & ZEND_ACC_IMPLICIT_PUBLIC)) {
    3650           1 :                         zend_error(E_COMPILE_ERROR, "Cannot redeclare %s::$%s", CG(active_class_entry)->name, var_name->u.constant.value.str.val);
    3651             :                 }
    3652             :         }
    3653        1940 :         ALLOC_ZVAL(property);
    3654             : 
    3655        1940 :         if (value) {
    3656        1073 :                 *property = value->u.constant;
    3657             :         } else {
    3658         867 :                 INIT_PZVAL(property);
    3659         867 :                 Z_TYPE_P(property) = IS_NULL;
    3660             :         }
    3661             : 
    3662        1940 :         if (CG(doc_comment)) {
    3663          42 :                 comment = CG(doc_comment);
    3664          42 :                 comment_len = CG(doc_comment_len);
    3665          42 :                 CG(doc_comment) = NULL;
    3666          42 :                 CG(doc_comment_len) = 0;
    3667             :         }
    3668             : 
    3669        1940 :         zend_declare_property_ex(CG(active_class_entry), var_name->u.constant.value.str.val, var_name->u.constant.value.str.len, property, access_type, comment, comment_len TSRMLS_CC);
    3670        1940 :         efree(var_name->u.constant.value.str.val);
    3671        1940 : }
    3672             : /* }}} */
    3673             : 
    3674         211 : void zend_do_declare_class_constant(znode *var_name, const znode *value TSRMLS_DC) /* {{{ */
    3675             : {
    3676             :         zval *property;
    3677             : 
    3678         211 :         if(Z_TYPE(value->u.constant) == IS_CONSTANT_ARRAY) {
    3679           2 :                 zend_error(E_COMPILE_ERROR, "Arrays are not allowed in class constants");
    3680             :         }
    3681             : 
    3682         209 :         ALLOC_ZVAL(property);
    3683         209 :         *property = value->u.constant;
    3684             : 
    3685         209 :         if (zend_hash_add(&CG(active_class_entry)->constants_table, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, &property, sizeof(zval *), NULL)==FAILURE) {
    3686           2 :                 FREE_ZVAL(property);
    3687           2 :                 zend_error(E_COMPILE_ERROR, "Cannot redefine class constant %s::%s", CG(active_class_entry)->name, var_name->u.constant.value.str.val);
    3688             :         }
    3689         207 :         FREE_PNODE(var_name);
    3690             :         
    3691         207 :         if (CG(doc_comment)) {
    3692           2 :                 efree(CG(doc_comment));
    3693           2 :                 CG(doc_comment) = NULL;
    3694           2 :                 CG(doc_comment_len) = 0;
    3695             :         }
    3696         207 : }
    3697             : /* }}} */
    3698             : 
    3699       44028 : void zend_do_fetch_property(znode *result, znode *object, const znode *property TSRMLS_DC) /* {{{ */
    3700             : {
    3701             :         zend_op opline;
    3702             :         zend_llist *fetch_list_ptr;
    3703             : 
    3704       44028 :         zend_stack_top(&CG(bp_stack), (void **) &fetch_list_ptr);
    3705             : 
    3706       44028 :         if (object->op_type == IS_CV) {
    3707       38157 :                 if (object->u.var == CG(active_op_array)->this_var) {
    3708           0 :                         SET_UNUSED(*object); /* this means $this for objects */
    3709             :                 }
    3710        5871 :         } else if (fetch_list_ptr->count == 1) {
    3711        5250 :                 zend_llist_element *le = fetch_list_ptr->head;
    3712        5250 :                 zend_op *opline_ptr = (zend_op *) le->data;
    3713             : 
    3714        5250 :                 if (opline_is_fetch_this(opline_ptr TSRMLS_CC)) {
    3715        3632 :                         efree(Z_STRVAL(opline_ptr->op1.u.constant));
    3716        3632 :                         SET_UNUSED(opline_ptr->op1); /* this means $this for objects */
    3717        3632 :                         opline_ptr->op2 = *property;
    3718             :                         /* if it was usual fetch, we change it to object fetch */
    3719        3632 :                         switch (opline_ptr->opcode) {
    3720             :                                 case ZEND_FETCH_W:
    3721        3632 :                                         opline_ptr->opcode = ZEND_FETCH_OBJ_W;
    3722        3632 :                                         break;
    3723             :                                 case ZEND_FETCH_R:
    3724           0 :                                         opline_ptr->opcode = ZEND_FETCH_OBJ_R;
    3725           0 :                                         break;
    3726             :                                 case ZEND_FETCH_RW:
    3727           0 :                                         opline_ptr->opcode = ZEND_FETCH_OBJ_RW;
    3728           0 :                                         break;
    3729             :                                 case ZEND_FETCH_IS:
    3730           0 :                                         opline_ptr->opcode = ZEND_FETCH_OBJ_IS;
    3731           0 :                                         break;
    3732             :                                 case ZEND_FETCH_UNSET:
    3733           0 :                                         opline_ptr->opcode = ZEND_FETCH_OBJ_UNSET;
    3734           0 :                                         break;
    3735             :                                 case ZEND_FETCH_FUNC_ARG:
    3736           0 :                                         opline_ptr->opcode = ZEND_FETCH_OBJ_FUNC_ARG;
    3737             :                                         break;
    3738             :                         }
    3739        3632 :                         *result = opline_ptr->result;
    3740        3632 :                         return;
    3741             :                 }
    3742             :         }
    3743             : 
    3744       40396 :         init_op(&opline TSRMLS_CC);
    3745       40396 :         opline.opcode = ZEND_FETCH_OBJ_W;       /* the backpatching routine assumes W */
    3746       40396 :         opline.result.op_type = IS_VAR;
    3747       40396 :         opline.result.u.EA.type = 0;
    3748       40396 :         opline.result.u.var = get_temporary_variable(CG(active_op_array));
    3749       40396 :         opline.op1 = *object;
    3750       40396 :         opline.op2 = *property;
    3751       40396 :         *result = opline.result;
    3752             : 
    3753       40396 :         zend_llist_add_element(fetch_list_ptr, &opline);
    3754             : }
    3755             : /* }}} */
    3756             : 
    3757         274 : void zend_do_halt_compiler_register(TSRMLS_D) /* {{{ */
    3758             : {
    3759             :         char *name, *cfilename;
    3760         274 :         char haltoff[] = "__COMPILER_HALT_OFFSET__";
    3761             :         int len, clen;
    3762             :         
    3763         274 :         if (CG(has_bracketed_namespaces) && CG(in_namespace)) {
    3764           1 :                 zend_error(E_COMPILE_ERROR, "__HALT_COMPILER() can only be used from the outermost scope");
    3765             :         }
    3766             :         
    3767         273 :         cfilename = zend_get_compiled_filename(TSRMLS_C);
    3768         273 :         clen = strlen(cfilename);
    3769         273 :         zend_mangle_property_name(&name, &len, haltoff, sizeof(haltoff) - 1, cfilename, clen, 0);
    3770         273 :         zend_register_long_constant(name, len+1, zend_get_scanned_file_offset(TSRMLS_C), CONST_CS, 0 TSRMLS_CC);
    3771         273 :         pefree(name, 0);
    3772             :         
    3773         273 :         if (CG(in_namespace)) {
    3774           1 :                 zend_do_end_namespace(TSRMLS_C);
    3775             :         }
    3776         273 : }
    3777             : /* }}} */
    3778             : 
    3779        9102 : void zend_do_declare_implicit_property(TSRMLS_D) /* {{{ */
    3780             : {
    3781             : /* Fixes bug #26182. Not sure why we needed to do this in the first place.
    3782             :    Has to be checked with Zeev.
    3783             : */
    3784             : #if ANDI_0
    3785             :         zend_op *opline_ptr;
    3786             :         zend_llist_element *le;
    3787             :         zend_llist *fetch_list_ptr;
    3788             : 
    3789             : 
    3790             :         zend_stack_top(&CG(bp_stack), (void **) &fetch_list_ptr);
    3791             : 
    3792             :         if (fetch_list_ptr->count != 1) {
    3793             :                 return;
    3794             :         }
    3795             : 
    3796             :         le = fetch_list_ptr->head;
    3797             :         opline_ptr = (zend_op *) le->data;
    3798             : 
    3799             :         if (opline_ptr->op1.op_type == IS_UNUSED
    3800             :                 && CG(active_class_entry)
    3801             :                 && opline_ptr->op2.op_type == IS_CONST
    3802             :                 && !zend_hash_exists(&CG(active_class_entry)->properties_info, opline_ptr->op2.u.constant.value.str.val, opline_ptr->op2.u.constant.value.str.len+1)) {
    3803             :                 znode property;
    3804             : 
    3805             :                 property = opline_ptr->op2;
    3806             :                 property.u.constant.value.str.val = estrndup(opline_ptr->op2.u.constant.value.str.val, opline_ptr->op2.u.constant.value.str.len);
    3807             :                 zend_do_declare_property(&property, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_IMPLICIT_PUBLIC TSRMLS_CC);
    3808             :         }
    3809             : #endif
    3810        9102 : }
    3811             : /* }}} */
    3812             : 
    3813      121366 : void zend_do_push_object(const znode *object TSRMLS_DC) /* {{{ */
    3814             : {
    3815      121366 :         zend_stack_push(&CG(object_stack), object, sizeof(znode));
    3816      121366 : }
    3817             : /* }}} */
    3818             : 
    3819      121366 : void zend_do_pop_object(znode *object TSRMLS_DC) /* {{{ */
    3820             : {
    3821      121366 :         if (object) {
    3822             :                 znode *tmp;
    3823             : 
    3824      121366 :                 zend_stack_top(&CG(object_stack), (void **) &tmp);
    3825      121366 :                 *object = *tmp;
    3826             :         }
    3827      121366 :         zend_stack_del_top(&CG(object_stack));
    3828      121366 : }
    3829             : /* }}} */
    3830             : 
    3831       13460 : void zend_do_begin_new_object(znode *new_token, znode *class_type TSRMLS_DC) /* {{{ */
    3832             : {
    3833             :         zend_op *opline;
    3834       13460 :         unsigned char *ptr = NULL;
    3835             : 
    3836       13460 :         new_token->u.opline_num = get_next_op_number(CG(active_op_array));
    3837       13460 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3838       13460 :         opline->opcode = ZEND_NEW;
    3839       13460 :         opline->result.op_type = IS_VAR;
    3840       13460 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    3841       13460 :         opline->op1 = *class_type;
    3842       13460 :         SET_UNUSED(opline->op2);
    3843             : 
    3844       13460 :         zend_stack_push(&CG(function_call_stack), (void *) &ptr, sizeof(unsigned char *));
    3845       13460 : }
    3846             : /* }}} */
    3847             : 
    3848       13460 : void zend_do_end_new_object(znode *result, const znode *new_token, const znode *argument_list TSRMLS_DC) /* {{{ */
    3849             : {
    3850             :         znode ctor_result;
    3851             : 
    3852       13460 :         zend_do_end_function_call(NULL, &ctor_result, argument_list, 1, 0 TSRMLS_CC);
    3853       13460 :         zend_do_free(&ctor_result TSRMLS_CC);
    3854             : 
    3855       13460 :         CG(active_op_array)->opcodes[new_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array));
    3856       13460 :         *result = CG(active_op_array)->opcodes[new_token->u.opline_num].result;
    3857       13460 : }
    3858             : /* }}} */
    3859             : 
    3860       87905 : static zend_constant* zend_get_ct_const(const zval *const_name, int all_internal_constants_substitution TSRMLS_DC) /* {{{ */
    3861             : {
    3862       87905 :         zend_constant *c = NULL;
    3863             : 
    3864       87905 :         if (Z_STRVAL_P(const_name)[0] == '\\') {
    3865          27 :                 if (zend_hash_find(EG(zend_constants), Z_STRVAL_P(const_name)+1, Z_STRLEN_P(const_name), (void **) &c) == FAILURE) {
    3866          26 :                         char *lookup_name = zend_str_tolower_dup(Z_STRVAL_P(const_name)+1, Z_STRLEN_P(const_name)-1);
    3867             : 
    3868          26 :                         if (zend_hash_find(EG(zend_constants), lookup_name, Z_STRLEN_P(const_name), (void **) &c)==SUCCESS) {
    3869           0 :                                 if ((c->flags & CONST_CT_SUBST) && !(c->flags & CONST_CS)) {
    3870           0 :                                         efree(lookup_name);
    3871           0 :                                         return c;
    3872             :                                 }
    3873             :                         }
    3874          26 :                         efree(lookup_name);
    3875          26 :                         return NULL;
    3876             :                 }
    3877       87878 :         } else if (zend_hash_find(EG(zend_constants), Z_STRVAL_P(const_name), Z_STRLEN_P(const_name)+1, (void **) &c) == FAILURE) {
    3878       26155 :                 char *lookup_name = zend_str_tolower_dup(Z_STRVAL_P(const_name), Z_STRLEN_P(const_name));
    3879             :                  
    3880       26155 :                 if (zend_hash_find(EG(zend_constants), lookup_name, Z_STRLEN_P(const_name)+1, (void **) &c)==SUCCESS) {
    3881       21891 :                         if ((c->flags & CONST_CT_SUBST) && !(c->flags & CONST_CS)) {
    3882       21590 :                                 efree(lookup_name);
    3883       21590 :                                 return c;
    3884             :                         }
    3885             :                 }
    3886        4565 :                 efree(lookup_name);
    3887        4565 :                 return NULL;
    3888             :         }
    3889       61724 :         if (c->flags & CONST_CT_SUBST) {
    3890       50952 :                 return c;
    3891             :         }
    3892       53164 :         if (all_internal_constants_substitution &&
    3893       10676 :                         (c->flags & CONST_PERSISTENT) &&
    3894       10572 :                         !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION) &&
    3895       10572 :                         Z_TYPE(c->value) != IS_CONSTANT &&
    3896       10572 :                         Z_TYPE(c->value) != IS_CONSTANT_ARRAY) {
    3897       10572 :                 return c;
    3898             :         }
    3899         200 :         return NULL;
    3900             : }
    3901             : /* }}} */
    3902             : 
    3903       87872 : static int zend_constant_ct_subst(znode *result, zval *const_name, int all_internal_constants_substitution TSRMLS_DC) /* {{{ */
    3904             : {
    3905       87872 :         zend_constant *c = zend_get_ct_const(const_name, all_internal_constants_substitution TSRMLS_CC);
    3906             : 
    3907       87872 :         if (c) {
    3908       83113 :                 zval_dtor(const_name);
    3909       83113 :                 result->op_type = IS_CONST;
    3910       83113 :                 result->u.constant = c->value;
    3911       83113 :                 zval_copy_ctor(&result->u.constant);
    3912       83113 :                 INIT_PZVAL(&result->u.constant);
    3913       83113 :                 return 1;
    3914             :         }
    3915        4759 :         return 0;
    3916             : }
    3917             : /* }}} */
    3918             : 
    3919       98071 : void zend_do_fetch_constant(znode *result, znode *constant_container, znode *constant_name, int mode, zend_bool check_namespace TSRMLS_DC) /* {{{ */
    3920             : {
    3921             :         znode tmp;
    3922             :         zend_op *opline;
    3923             :         int type;
    3924             :         char *compound;
    3925       98071 :         ulong fetch_type = 0;
    3926             : 
    3927       98071 :         if (constant_container) {
    3928       10199 :                 switch (mode) {
    3929             :                         case ZEND_CT:
    3930             :                                 /* this is a class constant */
    3931         339 :                                 type = zend_get_class_fetch_type(Z_STRVAL(constant_container->u.constant), Z_STRLEN(constant_container->u.constant));
    3932             :         
    3933         339 :                                 if (ZEND_FETCH_CLASS_STATIC == type) {
    3934           0 :                                         zend_error(E_ERROR, "\"static::\" is not allowed in compile-time constants");
    3935         339 :                                 } else if (ZEND_FETCH_CLASS_DEFAULT == type) {
    3936         290 :                                         zend_resolve_class_name(constant_container, &fetch_type, 1 TSRMLS_CC);
    3937             :                                 }
    3938         339 :                                 zend_do_build_full_name(NULL, constant_container, constant_name, 1 TSRMLS_CC);
    3939         339 :                                 *result = *constant_container;
    3940         339 :                                 result->u.constant.type = IS_CONSTANT | fetch_type;
    3941         339 :                                 break;
    3942             :                         case ZEND_RT:
    3943       29527 :                                 if (constant_container->op_type == IS_CONST &&
    3944        9856 :                                 ZEND_FETCH_CLASS_DEFAULT == zend_get_class_fetch_type(Z_STRVAL(constant_container->u.constant), Z_STRLEN(constant_container->u.constant))) {
    3945        9811 :                                         zend_resolve_class_name(constant_container, &fetch_type, 1 TSRMLS_CC);
    3946             :                                 } else {
    3947          49 :                                         zend_do_fetch_class(&tmp, constant_container TSRMLS_CC);
    3948          49 :                                         constant_container = &tmp;
    3949             :                                 }
    3950        9860 :                                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3951        9860 :                                 opline->opcode = ZEND_FETCH_CONSTANT;
    3952        9860 :                                 opline->result.op_type = IS_TMP_VAR;
    3953        9860 :                                 opline->result.u.var = get_temporary_variable(CG(active_op_array));
    3954        9860 :                                 opline->op1 = *constant_container;
    3955        9860 :                                 opline->op2 = *constant_name;
    3956        9860 :                                 *result = opline->result;
    3957             :                                 break;
    3958             :                 }
    3959       10199 :                 return;
    3960             :         }
    3961             :         /* namespace constant */
    3962             :         /* only one that did not contain \ from the start can be converted to string if unknown */
    3963       87872 :         switch (mode) {
    3964             :                 case ZEND_CT:
    3965        6860 :                         compound = memchr(Z_STRVAL(constant_name->u.constant), '\\', Z_STRLEN(constant_name->u.constant));
    3966             :                         /* this is a namespace constant, or an unprefixed constant */
    3967             : 
    3968        6860 :                         if (zend_constant_ct_subst(result, &constant_name->u.constant, 0 TSRMLS_CC)) {
    3969        6678 :                                 break;
    3970             :                         }
    3971             : 
    3972         182 :                         zend_resolve_non_class_name(constant_name, check_namespace TSRMLS_CC);
    3973             : 
    3974         182 :                         if(!compound) {
    3975         140 :                                 fetch_type |= IS_CONSTANT_UNQUALIFIED;
    3976             :                         }
    3977             : 
    3978         182 :                         *result = *constant_name;
    3979         182 :                         result->u.constant.type = IS_CONSTANT | fetch_type;
    3980         182 :                         break;
    3981             :                 case ZEND_RT:
    3982       81012 :                         compound = memchr(Z_STRVAL(constant_name->u.constant), '\\', Z_STRLEN(constant_name->u.constant));
    3983             : 
    3984       81012 :                         zend_resolve_non_class_name(constant_name, check_namespace TSRMLS_CC);
    3985             :                         
    3986       81012 :                         if(zend_constant_ct_subst(result, &constant_name->u.constant, 1 TSRMLS_CC)) {
    3987       76435 :                                 break;
    3988             :                         }
    3989             : 
    3990        4577 :                         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3991        4577 :                         opline->opcode = ZEND_FETCH_CONSTANT;
    3992        4577 :                         opline->result.op_type = IS_TMP_VAR;
    3993        4577 :                         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    3994        4577 :                         *result = opline->result;
    3995        4577 :                         SET_UNUSED(opline->op1);
    3996        4577 :                         if(compound) {
    3997             :                                 /* the name is unambiguous */
    3998          48 :                                 opline->extended_value = 0;
    3999             :                         } else {
    4000        4529 :                                 opline->extended_value = IS_CONSTANT_UNQUALIFIED;
    4001             :                         }
    4002        4577 :                         opline->op2 = *constant_name;
    4003             :                         break;
    4004             :         }
    4005             : }
    4006             : /* }}} */
    4007             : 
    4008         108 : void zend_do_shell_exec(znode *result, const znode *cmd TSRMLS_DC) /* {{{ */
    4009             : {
    4010         108 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4011             : 
    4012         108 :         switch (cmd->op_type) {
    4013             :                 case IS_CONST:
    4014             :                 case IS_TMP_VAR:
    4015         108 :                         opline->opcode = ZEND_SEND_VAL;
    4016         108 :                         break;
    4017             :                 default:
    4018           0 :                         opline->opcode = ZEND_SEND_VAR;
    4019             :                         break;
    4020             :         }
    4021         108 :         opline->op1 = *cmd;
    4022         108 :         opline->op2.u.opline_num = 1;
    4023         108 :         opline->extended_value = ZEND_DO_FCALL;
    4024         108 :         SET_UNUSED(opline->op2);
    4025             : 
    4026             :         /* FIXME: exception support not added to this op2 */
    4027         108 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4028         108 :         opline->opcode = ZEND_DO_FCALL;
    4029         108 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    4030         108 :         opline->result.op_type = IS_VAR;
    4031         108 :         Z_STRVAL(opline->op1.u.constant) = estrndup("shell_exec", sizeof("shell_exec")-1);
    4032         108 :         Z_STRLEN(opline->op1.u.constant) = sizeof("shell_exec")-1;
    4033         108 :         INIT_PZVAL(&opline->op1.u.constant);
    4034         108 :         Z_TYPE(opline->op1.u.constant) = IS_STRING;
    4035         108 :         opline->op1.op_type = IS_CONST;
    4036         108 :         opline->extended_value = 1;
    4037         108 :         SET_UNUSED(opline->op2);
    4038         108 :         ZVAL_LONG(&opline->op2.u.constant, zend_hash_func("shell_exec", sizeof("shell_exec")));
    4039         108 :         *result = opline->result;
    4040         108 : }
    4041             : /* }}} */
    4042             : 
    4043       26876 : void zend_do_init_array(znode *result, const znode *expr, const znode *offset, zend_bool is_ref TSRMLS_DC) /* {{{ */
    4044             : {
    4045       26876 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4046             : 
    4047       26876 :         opline->opcode = ZEND_INIT_ARRAY;
    4048       26876 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    4049       26876 :         opline->result.op_type = IS_TMP_VAR;
    4050       26876 :         *result = opline->result;
    4051       26876 :         if (expr) {
    4052       23727 :                 opline->op1 = *expr;
    4053       23727 :                 if (offset) {
    4054       10325 :                         opline->op2 = *offset;
    4055             :                 } else {
    4056       13402 :                         SET_UNUSED(opline->op2);
    4057             :                 }
    4058             :         } else {
    4059        3149 :                 SET_UNUSED(opline->op1);
    4060        3149 :                 SET_UNUSED(opline->op2);
    4061             :         }
    4062       26876 :         opline->extended_value = is_ref;
    4063       26876 : }
    4064             : /* }}} */
    4065             : 
    4066       82511 : void zend_do_add_array_element(znode *result, const znode *expr, const znode *offset, zend_bool is_ref TSRMLS_DC) /* {{{ */
    4067             : {
    4068       82511 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4069             : 
    4070       82511 :         opline->opcode = ZEND_ADD_ARRAY_ELEMENT;
    4071       82511 :         opline->result = *result;
    4072       82511 :         opline->op1 = *expr;
    4073       82511 :         if (offset) {
    4074       30839 :                 opline->op2 = *offset;
    4075             :         } else {
    4076       51672 :                 SET_UNUSED(opline->op2);
    4077             :         }
    4078       82511 :         opline->extended_value = is_ref;
    4079       82511 : }
    4080             : /* }}} */
    4081             : 
    4082        3464 : void zend_do_add_static_array_element(znode *result, znode *offset, const znode *expr) /* {{{ */
    4083             : {
    4084             :         zval *element;
    4085             : 
    4086        3464 :         ALLOC_ZVAL(element);
    4087        3464 :         *element = expr->u.constant;
    4088        3464 :         if (offset) {
    4089         139 :                 switch (offset->u.constant.type & IS_CONSTANT_TYPE_MASK) {
    4090             :                         case IS_CONSTANT:
    4091             :                                 /* Ugly hack to denote that this value has a constant index */
    4092          81 :                                 Z_TYPE_P(element) |= IS_CONSTANT_INDEX;
    4093          81 :                                 Z_STRVAL(offset->u.constant) = erealloc(Z_STRVAL(offset->u.constant), Z_STRLEN(offset->u.constant)+3);
    4094          81 :                                 Z_STRVAL(offset->u.constant)[Z_STRLEN(offset->u.constant)+1] = Z_TYPE(offset->u.constant);
    4095          81 :                                 Z_STRVAL(offset->u.constant)[Z_STRLEN(offset->u.constant)+2] = 0;
    4096          81 :                                 zend_symtable_update(result->u.constant.value.ht, Z_STRVAL(offset->u.constant), Z_STRLEN(offset->u.constant)+3, &element, sizeof(zval *), NULL);
    4097          81 :                                 zval_dtor(&offset->u.constant);
    4098          81 :                                 break;
    4099             :                         case IS_STRING:
    4100          36 :                                 zend_symtable_update(result->u.constant.value.ht, offset->u.constant.value.str.val, offset->u.constant.value.str.len+1, &element, sizeof(zval *), NULL);
    4101          36 :                                 zval_dtor(&offset->u.constant);
    4102          36 :                                 break;
    4103             :                         case IS_NULL:
    4104           0 :                                 zend_symtable_update(Z_ARRVAL(result->u.constant), "", 1, &element, sizeof(zval *), NULL);
    4105           0 :                                 break;
    4106             :                         case IS_LONG:
    4107             :                         case IS_BOOL:
    4108          22 :                                 zend_hash_index_update(Z_ARRVAL(result->u.constant), Z_LVAL(offset->u.constant), &element, sizeof(zval *), NULL);
    4109          22 :                                 break;
    4110             :                         case IS_DOUBLE:
    4111           0 :                                 zend_hash_index_update(Z_ARRVAL(result->u.constant), zend_dval_to_lval(Z_DVAL(offset->u.constant)), &element, sizeof(zval *), NULL);
    4112           0 :                                 break;
    4113             :                         case IS_CONSTANT_ARRAY:
    4114           0 :                                 zend_error(E_ERROR, "Illegal offset type");
    4115             :                                 break;
    4116             :                 }
    4117             :         } else {
    4118        3325 :                 zend_hash_next_index_insert(Z_ARRVAL(result->u.constant), &element, sizeof(zval *), NULL);
    4119             :         }
    4120        3464 : }
    4121             : /* }}} */
    4122             : 
    4123         263 : void zend_do_add_list_element(const znode *element TSRMLS_DC) /* {{{ */
    4124             : {
    4125             :         list_llist_element lle;
    4126             : 
    4127         263 :         if (element) {
    4128         246 :                 zend_check_writable_variable(element);
    4129             : 
    4130         246 :                 lle.var = *element;
    4131         246 :                 zend_llist_copy(&lle.dimensions, &CG(dimension_llist));
    4132         246 :                 zend_llist_prepend_element(&CG(list_llist), &lle);
    4133             :         }
    4134         263 :         (*((int *)CG(dimension_llist).tail->data))++;
    4135         263 : }
    4136             : /* }}} */
    4137             : 
    4138         117 : void zend_do_new_list_begin(TSRMLS_D) /* {{{ */
    4139             : {
    4140         117 :         int current_dimension = 0;
    4141         117 :         zend_llist_add_element(&CG(dimension_llist), &current_dimension);
    4142         117 : }
    4143             : /* }}} */
    4144             : 
    4145          12 : void zend_do_new_list_end(TSRMLS_D) /* {{{ */
    4146             : {
    4147          12 :         zend_llist_remove_tail(&CG(dimension_llist));
    4148          12 :         (*((int *)CG(dimension_llist).tail->data))++;
    4149          12 : }
    4150             : /* }}} */
    4151             : 
    4152         105 : void zend_do_list_init(TSRMLS_D) /* {{{ */
    4153             : {
    4154         105 :         zend_stack_push(&CG(list_stack), &CG(list_llist), sizeof(zend_llist));
    4155         105 :         zend_stack_push(&CG(list_stack), &CG(dimension_llist), sizeof(zend_llist));
    4156         105 :         zend_llist_init(&CG(list_llist), sizeof(list_llist_element), NULL, 0);
    4157         105 :         zend_llist_init(&CG(dimension_llist), sizeof(int), NULL, 0);
    4158         105 :         zend_do_new_list_begin(TSRMLS_C);
    4159         105 : }
    4160             : /* }}} */
    4161             : 
    4162         105 : void zend_do_list_end(znode *result, znode *expr TSRMLS_DC) /* {{{ */
    4163             : {
    4164             :         zend_llist_element *le;
    4165             :         zend_llist_element *dimension;
    4166             :         zend_op *opline;
    4167             :         znode last_container;
    4168             : 
    4169         105 :         le = CG(list_llist).head;
    4170         456 :         while (le) {
    4171         246 :                 zend_llist *tmp_dimension_llist = &((list_llist_element *)le->data)->dimensions;
    4172         246 :                 dimension = tmp_dimension_llist->head;
    4173         763 :                 while (dimension) {
    4174         271 :                         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4175         271 :                         if (dimension == tmp_dimension_llist->head) { /* first */
    4176         246 :                                 last_container = *expr;
    4177         246 :                                 switch (expr->op_type) {
    4178             :                                         case IS_VAR:
    4179             :                                         case IS_CV:
    4180         180 :                                                 opline->opcode = ZEND_FETCH_DIM_R;
    4181         180 :                                                 break;
    4182             :                                         case IS_TMP_VAR:
    4183          60 :                                                 opline->opcode = ZEND_FETCH_DIM_TMP_VAR;
    4184          60 :                                                 break;
    4185             :                                         case IS_CONST: /* fetch_dim_tmp_var will handle this bogus fetch */
    4186           6 :                                                 zval_copy_ctor(&expr->u.constant);
    4187           6 :                                                 opline->opcode = ZEND_FETCH_DIM_TMP_VAR;
    4188             :                                                 break;
    4189             :                                 }
    4190         246 :                                 opline->extended_value = ZEND_FETCH_ADD_LOCK;
    4191             :                         } else {
    4192          25 :                                 opline->opcode = ZEND_FETCH_DIM_R;
    4193             :                         }
    4194         271 :                         opline->result.op_type = IS_VAR;
    4195         271 :                         opline->result.u.EA.type = 0;
    4196         271 :                         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    4197         271 :                         opline->op1 = last_container;
    4198         271 :                         opline->op2.op_type = IS_CONST;
    4199         271 :                         Z_TYPE(opline->op2.u.constant) = IS_LONG;
    4200         271 :                         Z_LVAL(opline->op2.u.constant) = *((int *) dimension->data);
    4201         271 :                         INIT_PZVAL(&opline->op2.u.constant);
    4202         271 :                         last_container = opline->result;
    4203         271 :                         dimension = dimension->next;
    4204             :                 }
    4205         246 :                 ((list_llist_element *) le->data)->value = last_container;
    4206         246 :                 zend_llist_destroy(&((list_llist_element *) le->data)->dimensions);
    4207         246 :                 zend_do_assign(result, &((list_llist_element *) le->data)->var, &((list_llist_element *) le->data)->value TSRMLS_CC);
    4208         246 :                 zend_do_free(result TSRMLS_CC);
    4209         246 :                 le = le->next;
    4210             :         }
    4211         105 :         zend_llist_destroy(&CG(dimension_llist));
    4212         105 :         zend_llist_destroy(&CG(list_llist));
    4213         105 :         *result = *expr;
    4214             :         {
    4215             :                 zend_llist *p;
    4216             : 
    4217             :                 /* restore previous lists */
    4218         105 :                 zend_stack_top(&CG(list_stack), (void **) &p);
    4219         105 :                 CG(dimension_llist) = *p;
    4220         105 :                 zend_stack_del_top(&CG(list_stack));
    4221         105 :                 zend_stack_top(&CG(list_stack), (void **) &p);
    4222         105 :                 CG(list_llist) = *p;
    4223         105 :                 zend_stack_del_top(&CG(list_stack));
    4224             :         }
    4225         105 : }
    4226             : /* }}} */
    4227             : 
    4228        2106 : void zend_do_fetch_static_variable(znode *varname, const znode *static_assignment, int fetch_type TSRMLS_DC) /* {{{ */
    4229             : {
    4230             :         zval *tmp;
    4231             :         zend_op *opline;
    4232             :         znode lval;
    4233             :         znode result;
    4234             : 
    4235        2106 :         ALLOC_ZVAL(tmp);
    4236             : 
    4237        2106 :         if (static_assignment) {
    4238        2086 :                 *tmp = static_assignment->u.constant;
    4239             :         } else {
    4240          20 :                 INIT_ZVAL(*tmp);
    4241             :         }
    4242        2106 :         if (!CG(active_op_array)->static_variables) {
    4243        2080 :                 ALLOC_HASHTABLE(CG(active_op_array)->static_variables);
    4244        2080 :                 zend_hash_init(CG(active_op_array)->static_variables, 2, NULL, ZVAL_PTR_DTOR, 0);
    4245             :         }
    4246        2106 :         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);
    4247             : 
    4248        2106 :         if (varname->op_type == IS_CONST) {
    4249        2106 :                 if (Z_TYPE(varname->u.constant) != IS_STRING) {
    4250           0 :                         convert_to_string(&varname->u.constant);
    4251             :                 }
    4252             :         }
    4253             : 
    4254        2106 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4255        2106 :         opline->opcode = (fetch_type == ZEND_FETCH_LEXICAL) ? ZEND_FETCH_R : ZEND_FETCH_W;           /* the default mode must be Write, since fetch_simple_variable() is used to define function arguments */
    4256        2106 :         opline->result.op_type = IS_VAR;
    4257        2106 :         opline->result.u.EA.type = 0;
    4258        2106 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    4259        2106 :         opline->op1 = *varname;
    4260        2106 :         SET_UNUSED(opline->op2);
    4261        2106 :         opline->op2.u.EA.type = ZEND_FETCH_STATIC;
    4262        2106 :         result = opline->result;
    4263             : 
    4264        2106 :         if (varname->op_type == IS_CONST) {
    4265        2106 :                 zval_copy_ctor(&varname->u.constant);
    4266             :         }
    4267        2106 :         fetch_simple_variable(&lval, varname, 0 TSRMLS_CC); /* Relies on the fact that the default fetch is BP_VAR_W */
    4268             : 
    4269        2106 :         if (fetch_type == ZEND_FETCH_LEXICAL) {
    4270             :                 znode dummy;
    4271             : 
    4272          30 :                 zend_do_begin_variable_parse(TSRMLS_C);
    4273          30 :                 zend_do_assign(&dummy, &lval, &result TSRMLS_CC);
    4274          30 :                 zend_do_free(&dummy TSRMLS_CC);
    4275             :         } else {
    4276        2076 :                 zend_do_assign_ref(NULL, &lval, &result TSRMLS_CC);
    4277             :         }
    4278        2106 :         CG(active_op_array)->opcodes[CG(active_op_array)->last-1].result.u.EA.type |= EXT_TYPE_UNUSED;
    4279             : 
    4280             : /*      zval_dtor(&varname->u.constant); */
    4281        2106 : }
    4282             : /* }}} */
    4283             : 
    4284          49 : void zend_do_fetch_lexical_variable(znode *varname, zend_bool is_ref TSRMLS_DC) /* {{{ */
    4285             : {
    4286             :         znode value;
    4287             : 
    4288          50 :         if (Z_STRLEN(varname->u.constant) == sizeof("this") - 1 &&
    4289           1 :                         memcmp(Z_STRVAL(varname->u.constant), "this", sizeof("this") - 1) == 0) {
    4290           0 :                 zend_error(E_COMPILE_ERROR, "Cannot use $this as lexical variable");
    4291           0 :                 return;
    4292             :         }
    4293             : 
    4294          49 :         value.op_type = IS_CONST;
    4295          49 :         ZVAL_NULL(&value.u.constant);
    4296          49 :         Z_TYPE(value.u.constant) |= is_ref ? IS_LEXICAL_REF : IS_LEXICAL_VAR;
    4297             :         Z_SET_REFCOUNT_P(&value.u.constant, 1);
    4298             :         Z_UNSET_ISREF_P(&value.u.constant);
    4299             :         
    4300          49 :         zend_do_fetch_static_variable(varname, &value, is_ref ? ZEND_FETCH_STATIC : ZEND_FETCH_LEXICAL TSRMLS_CC);
    4301             : }
    4302             : /* }}} */
    4303             : 
    4304        5343 : void zend_do_fetch_global_variable(znode *varname, const znode *static_assignment, int fetch_type TSRMLS_DC) /* {{{ */
    4305             : {
    4306             :         zend_op *opline;
    4307             :         znode lval;
    4308             :         znode result;
    4309             : 
    4310        5343 :         if (varname->op_type == IS_CONST) {
    4311        5341 :                 if (Z_TYPE(varname->u.constant) != IS_STRING) {
    4312           0 :                         convert_to_string(&varname->u.constant);
    4313             :                 }
    4314             :         }
    4315             : 
    4316        5343 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4317        5343 :         opline->opcode = ZEND_FETCH_W;               /* the default mode must be Write, since fetch_simple_variable() is used to define function arguments */
    4318        5343 :         opline->result.op_type = IS_VAR;
    4319        5343 :         opline->result.u.EA.type = 0;
    4320        5343 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    4321        5343 :         opline->op1 = *varname;
    4322        5343 :         SET_UNUSED(opline->op2);
    4323        5343 :         opline->op2.u.EA.type = fetch_type;
    4324        5343 :         result = opline->result;
    4325             : 
    4326        5343 :         if (varname->op_type == IS_CONST) {
    4327        5341 :                 zval_copy_ctor(&varname->u.constant);
    4328             :         }
    4329        5343 :         fetch_simple_variable(&lval, varname, 0 TSRMLS_CC); /* Relies on the fact that the default fetch is BP_VAR_W */
    4330             : 
    4331        5343 :         zend_do_assign_ref(NULL, &lval, &result TSRMLS_CC);
    4332        5343 :         CG(active_op_array)->opcodes[CG(active_op_array)->last-1].result.u.EA.type |= EXT_TYPE_UNUSED;
    4333        5343 : }
    4334             : /* }}} */
    4335             : 
    4336        6607 : void zend_do_cast(znode *result, const znode *expr, int type TSRMLS_DC) /* {{{ */
    4337             : {
    4338        6607 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4339             : 
    4340        6607 :         opline->opcode = ZEND_CAST;
    4341        6607 :         opline->result.op_type = IS_TMP_VAR;
    4342        6607 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    4343        6607 :         opline->op1 = *expr;
    4344        6607 :         SET_UNUSED(opline->op2);
    4345        6607 :         opline->extended_value = type;
    4346        6607 :         *result = opline->result;
    4347        6607 : }
    4348             : /* }}} */
    4349             : 
    4350       12744 : void zend_do_include_or_eval(int type, znode *result, const znode *op1 TSRMLS_DC) /* {{{ */
    4351             : {
    4352       12744 :         zend_do_extended_fcall_begin(TSRMLS_C);
    4353             :         {
    4354       12744 :                 zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4355             : 
    4356       12744 :                 opline->opcode = ZEND_INCLUDE_OR_EVAL;
    4357       12744 :                 opline->result.op_type = IS_VAR;
    4358       12744 :                 opline->result.u.var = get_temporary_variable(CG(active_op_array));
    4359       12744 :                 opline->op1 = *op1;
    4360       12744 :                 SET_UNUSED(opline->op2);
    4361       12744 :                 Z_LVAL(opline->op2.u.constant) = type;
    4362       12744 :                 *result = opline->result;
    4363             :         }
    4364       12744 :         zend_do_extended_fcall_end(TSRMLS_C);
    4365       12744 : }
    4366             : /* }}} */
    4367             : 
    4368         144 : void zend_do_indirect_references(znode *result, const znode *num_references, znode *variable TSRMLS_DC) /* {{{ */
    4369             : {
    4370             :         int i;
    4371             : 
    4372         144 :         zend_do_end_variable_parse(variable, BP_VAR_R, 0 TSRMLS_CC);
    4373         154 :         for (i=1; i<num_references->u.constant.value.lval; i++) {
    4374          10 :                 fetch_simple_variable_ex(result, variable, 0, ZEND_FETCH_R TSRMLS_CC);
    4375          10 :                 *variable = *result;
    4376             :         }
    4377         144 :         zend_do_begin_variable_parse(TSRMLS_C);
    4378         144 :         fetch_simple_variable(result, variable, 1 TSRMLS_CC);
    4379             :         /* there is a chance someone is accessing $this */
    4380         144 :         if (CG(active_op_array)->scope && CG(active_op_array)->this_var == -1) {
    4381           1 :                 CG(active_op_array)->this_var = lookup_cv(CG(active_op_array), estrndup("this", sizeof("this")-1), sizeof("this")-1);
    4382             :         }
    4383         144 : }
    4384             : /* }}} */
    4385             : 
    4386        1582 : void zend_do_unset(const znode *variable TSRMLS_DC) /* {{{ */
    4387             : {
    4388             :         zend_op *last_op;
    4389             : 
    4390        1582 :         zend_check_writable_variable(variable);
    4391             : 
    4392        1582 :         if (variable->op_type == IS_CV) {
    4393        1290 :                 zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4394        1290 :                 opline->opcode = ZEND_UNSET_VAR;
    4395        1290 :                 opline->op1 = *variable;
    4396        1290 :                 SET_UNUSED(opline->op2);
    4397        1290 :                 opline->op2.u.EA.type = ZEND_FETCH_LOCAL;
    4398        1290 :                 SET_UNUSED(opline->result);
    4399        1290 :                 opline->extended_value = ZEND_QUICK_SET;
    4400             :         } else {
    4401         292 :                 last_op = &CG(active_op_array)->opcodes[get_next_op_number(CG(active_op_array))-1];
    4402             : 
    4403         292 :                 switch (last_op->opcode) {
    4404             :                         case ZEND_FETCH_UNSET:
    4405           8 :                                 last_op->opcode = ZEND_UNSET_VAR;
    4406           8 :                                 break;
    4407             :                         case ZEND_FETCH_DIM_UNSET:
    4408         209 :                                 last_op->opcode = ZEND_UNSET_DIM;
    4409         209 :                                 break;
    4410             :                         case ZEND_FETCH_OBJ_UNSET:
    4411          75 :                                 last_op->opcode = ZEND_UNSET_OBJ;
    4412             :                                 break;
    4413             : 
    4414             :                 }
    4415             :         }
    4416        1582 : }
    4417             : /* }}} */
    4418             : 
    4419       13131 : void zend_do_isset_or_isempty(int type, znode *result, znode *variable TSRMLS_DC) /* {{{ */
    4420             : {
    4421             :         zend_op *last_op;
    4422             : 
    4423       13131 :         zend_do_end_variable_parse(variable, BP_VAR_IS, 0 TSRMLS_CC);
    4424             : 
    4425       13130 :         zend_check_writable_variable(variable);
    4426             : 
    4427       13130 :         if (variable->op_type == IS_CV) {
    4428        4113 :                 last_op = get_next_op(CG(active_op_array) TSRMLS_CC);
    4429        4113 :                 last_op->opcode = ZEND_ISSET_ISEMPTY_VAR;
    4430        4113 :                 last_op->op1 = *variable;
    4431        4113 :                 SET_UNUSED(last_op->op2);
    4432        4113 :                 last_op->op2.u.EA.type = ZEND_FETCH_LOCAL;
    4433        4113 :                 last_op->result.u.var = get_temporary_variable(CG(active_op_array));
    4434        4113 :                 last_op->extended_value = ZEND_QUICK_SET;
    4435             :         } else {
    4436        9017 :                 last_op = &CG(active_op_array)->opcodes[get_next_op_number(CG(active_op_array))-1];
    4437             : 
    4438        9017 :                 switch (last_op->opcode) {
    4439             :                         case ZEND_FETCH_IS:
    4440          23 :                                 last_op->opcode = ZEND_ISSET_ISEMPTY_VAR;
    4441          23 :                                 break;
    4442             :                         case ZEND_FETCH_DIM_IS:
    4443        8284 :                                 last_op->opcode = ZEND_ISSET_ISEMPTY_DIM_OBJ;
    4444        8284 :                                 break;
    4445             :                         case ZEND_FETCH_OBJ_IS:
    4446         710 :                                 last_op->opcode = ZEND_ISSET_ISEMPTY_PROP_OBJ;
    4447             :                                 break;
    4448             :                 }
    4449        9017 :                 last_op->extended_value = 0;
    4450             :         }
    4451       13130 :         last_op->result.op_type = IS_TMP_VAR;
    4452       13130 :         last_op->extended_value |= type;
    4453             : 
    4454       13130 :         *result = last_op->result;
    4455       13130 : }
    4456             : /* }}} */
    4457             : 
    4458          63 : void zend_do_instanceof(znode *result, const znode *expr, const znode *class_znode, int type TSRMLS_DC) /* {{{ */
    4459             : {
    4460          63 :         int last_op_number = get_next_op_number(CG(active_op_array));
    4461             :         zend_op *opline;
    4462             : 
    4463          63 :         if (last_op_number > 0) {
    4464          63 :                 opline = &CG(active_op_array)->opcodes[last_op_number-1];
    4465          63 :                 if (opline->opcode == ZEND_FETCH_CLASS) {
    4466          63 :                         opline->extended_value |= ZEND_FETCH_CLASS_NO_AUTOLOAD;
    4467             :                 }
    4468             :         }
    4469             : 
    4470          63 :         if (expr->op_type == IS_CONST) {
    4471           1 :                 zend_error(E_COMPILE_ERROR, "instanceof expects an object instance, constant given");
    4472             :         }
    4473             : 
    4474          62 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4475          62 :         opline->opcode = ZEND_INSTANCEOF;
    4476          62 :         opline->result.op_type = IS_TMP_VAR;
    4477          62 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    4478          62 :         opline->op1 = *expr;
    4479             : 
    4480          62 :         opline->op2 = *class_znode;
    4481             : 
    4482          62 :         *result = opline->result;
    4483          62 : }
    4484             : /* }}} */
    4485             : 
    4486       11163 : void zend_do_foreach_begin(znode *foreach_token, znode *open_brackets_token, znode *array, znode *as_token, int variable TSRMLS_DC) /* {{{ */
    4487             : {
    4488             :         zend_op *opline;
    4489             :         zend_bool is_variable;
    4490       11163 :         zend_bool push_container = 0;
    4491             :         zend_op dummy_opline;
    4492             : 
    4493       11163 :         if (variable) {
    4494       10864 :                 if (zend_is_function_or_method_call(array)) {
    4495        1625 :                         is_variable = 0;
    4496             :                 } else {
    4497        9239 :                         is_variable = 1;
    4498             :                 }
    4499             :                 /* save the location of FETCH_W instruction(s) */
    4500       10864 :                 open_brackets_token->u.opline_num = get_next_op_number(CG(active_op_array));
    4501       10864 :                 zend_do_end_variable_parse(array, BP_VAR_W, 0 TSRMLS_CC);
    4502       21718 :                 if (CG(active_op_array)->last > 0 &&
    4503       10854 :                                 CG(active_op_array)->opcodes[CG(active_op_array)->last-1].opcode == ZEND_FETCH_OBJ_W) {
    4504             :                         /* Only lock the container if we are fetching from a real container and not $this */
    4505          31 :                         if (CG(active_op_array)->opcodes[CG(active_op_array)->last-1].op1.op_type == IS_VAR) {
    4506           7 :                                 CG(active_op_array)->opcodes[CG(active_op_array)->last-1].extended_value |= ZEND_FETCH_ADD_LOCK;
    4507           7 :                                 push_container = 1;
    4508             :                         }
    4509             :                 }
    4510             :         } else {
    4511         299 :                 is_variable = 0;
    4512         299 :                 open_brackets_token->u.opline_num = get_next_op_number(CG(active_op_array));
    4513             :         }
    4514             : 
    4515             :         /* save the location of FE_RESET */
    4516       11163 :         foreach_token->u.opline_num = get_next_op_number(CG(active_op_array));
    4517             : 
    4518       11163 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4519             : 
    4520             :         /* Preform array reset */
    4521       11163 :         opline->opcode = ZEND_FE_RESET;
    4522       11163 :         opline->result.op_type = IS_VAR;
    4523       11163 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    4524       11163 :         opline->op1 = *array;
    4525       11163 :         SET_UNUSED(opline->op2);
    4526       11163 :         opline->extended_value = is_variable ? ZEND_FE_RESET_VARIABLE : 0;
    4527             : 
    4528       11163 :         dummy_opline.result = opline->result;
    4529       11163 :         if (push_container) {
    4530           7 :                 dummy_opline.op1 = CG(active_op_array)->opcodes[CG(active_op_array)->last-2].op1;
    4531             :         } else {
    4532             :                 znode tmp;
    4533             : 
    4534       11156 :                 tmp.op_type = IS_UNUSED;
    4535       11156 :                 dummy_opline.op1 = tmp;
    4536             :         }
    4537       11163 :         zend_stack_push(&CG(foreach_copy_stack), (void *) &dummy_opline, sizeof(zend_op));
    4538             : 
    4539             :         /* save the location of FE_FETCH */
    4540       11163 :         as_token->u.opline_num = get_next_op_number(CG(active_op_array));
    4541             : 
    4542       11163 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4543       11163 :         opline->opcode = ZEND_FE_FETCH;
    4544       11163 :         opline->result.op_type = IS_VAR;
    4545       11163 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    4546       11163 :         opline->op1 = dummy_opline.result;
    4547       11163 :         opline->extended_value = 0;
    4548       11163 :         SET_UNUSED(opline->op2);
    4549             : 
    4550       11163 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4551       11163 :         opline->opcode = ZEND_OP_DATA;
    4552       11163 :         SET_UNUSED(opline->op1);
    4553       11163 :         SET_UNUSED(opline->op2);
    4554       11163 :         SET_UNUSED(opline->result);
    4555       11163 : }
    4556             : /* }}} */
    4557             : 
    4558       11162 : void zend_do_foreach_cont(znode *foreach_token, const znode *open_brackets_token, const znode *as_token, znode *value, znode *key TSRMLS_DC) /* {{{ */
    4559             : {
    4560             :         zend_op *opline;
    4561             :         znode dummy, value_node;
    4562       11162 :         zend_bool assign_by_ref=0;
    4563             : 
    4564       11162 :         opline = &CG(active_op_array)->opcodes[as_token->u.opline_num];
    4565       11162 :         if (key->op_type != IS_UNUSED) {
    4566             :                 znode *tmp;
    4567             : 
    4568             :                 /* switch between the key and value... */
    4569        5012 :                 tmp = key;
    4570        5012 :                 key = value;
    4571        5012 :                 value = tmp;
    4572             : 
    4573             :                 /* Mark extended_value in case both key and value are being used */
    4574        5012 :                 opline->extended_value |= ZEND_FE_FETCH_WITH_KEY;
    4575             :         }
    4576             : 
    4577       11162 :         if ((key->op_type != IS_UNUSED) && (key->u.EA.type & ZEND_PARSED_REFERENCE_VARIABLE)) {
    4578           2 :                 zend_error(E_COMPILE_ERROR, "Key element cannot be a reference");
    4579             :         }
    4580             : 
    4581       11160 :         if (value->u.EA.type & ZEND_PARSED_REFERENCE_VARIABLE) {
    4582          66 :                 assign_by_ref = 1;
    4583          66 :                 if (!(opline-1)->extended_value) {
    4584           2 :                         zend_error(E_COMPILE_ERROR, "Cannot create references to elements of a temporary array expression");
    4585             :                 }
    4586             :                 /* Mark extended_value for assign-by-reference */
    4587          64 :                 opline->extended_value |= ZEND_FE_FETCH_BYREF;
    4588          64 :                 CG(active_op_array)->opcodes[foreach_token->u.opline_num].extended_value |= ZEND_FE_RESET_REFERENCE;
    4589             :         } else {
    4590             :                 zend_op *foreach_copy;
    4591       11094 :                 zend_op *fetch = &CG(active_op_array)->opcodes[foreach_token->u.opline_num];
    4592       11094 :                 zend_op *end = &CG(active_op_array)->opcodes[open_brackets_token->u.opline_num];
    4593             : 
    4594             :                 /* Change "write context" into "read context" */
    4595       11094 :                 fetch->extended_value = 0;  /* reset ZEND_FE_RESET_VARIABLE */
    4596       24630 :                 while (fetch != end) {
    4597        2445 :                         --fetch;
    4598        2445 :                         if (fetch->opcode == ZEND_FETCH_DIM_W && fetch->op2.op_type == IS_UNUSED) {
    4599           3 :                                 zend_error(E_COMPILE_ERROR, "Cannot use [] for reading");
    4600             :                         }
    4601        2442 :                         fetch->opcode -= 3; /* FETCH_W -> FETCH_R */
    4602             :                 }
    4603             :                 /* prevent double SWITCH_FREE */
    4604       11091 :                 zend_stack_top(&CG(foreach_copy_stack), (void **) &foreach_copy);
    4605       11091 :                 foreach_copy->op1.op_type = IS_UNUSED;
    4606             :         }
    4607             : 
    4608       11155 :         value_node = opline->result;
    4609             : 
    4610       11155 :         if (assign_by_ref) {
    4611          64 :                 zend_do_end_variable_parse(value, BP_VAR_W, 0 TSRMLS_CC);
    4612             :                 /* Mark FE_FETCH as IS_VAR as it holds the data directly as a value */
    4613          64 :                 zend_do_assign_ref(NULL, value, &value_node TSRMLS_CC);
    4614             :         } else {
    4615       11091 :                 zend_do_assign(&dummy, value, &value_node TSRMLS_CC);
    4616       11091 :                 zend_do_free(&dummy TSRMLS_CC);
    4617             :         }
    4618             : 
    4619       11155 :         if (key->op_type != IS_UNUSED) {
    4620             :                 znode key_node;
    4621             : 
    4622        5008 :                 opline = &CG(active_op_array)->opcodes[as_token->u.opline_num+1];
    4623        5008 :                 opline->result.op_type = IS_TMP_VAR;
    4624        5008 :                 opline->result.u.EA.type = 0;
    4625        5008 :                 opline->result.u.opline_num = get_temporary_variable(CG(active_op_array));
    4626        5008 :                 key_node = opline->result;
    4627             : 
    4628        5008 :                 zend_do_assign(&dummy, key, &key_node TSRMLS_CC);
    4629        5008 :                 zend_do_free(&dummy TSRMLS_CC);
    4630             :         }
    4631             : 
    4632       11155 :         do_begin_loop(TSRMLS_C);
    4633       11155 :         INC_BPC(CG(active_op_array));
    4634       11155 : }
    4635             : /* }}} */
    4636             : 
    4637       11155 : void zend_do_foreach_end(const znode *foreach_token, const znode *as_token TSRMLS_DC) /* {{{ */
    4638             : {
    4639             :         zend_op *container_ptr;
    4640       11155 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4641             : 
    4642       11155 :         opline->opcode = ZEND_JMP;
    4643       11155 :         opline->op1.u.opline_num = as_token->u.opline_num;
    4644       11155 :         SET_UNUSED(opline->op1);
    4645       11155 :         SET_UNUSED(opline->op2);
    4646             : 
    4647       11155 :         CG(active_op_array)->opcodes[foreach_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array)); /* FE_RESET */
    4648       11155 :         CG(active_op_array)->opcodes[as_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array)); /* FE_FETCH */
    4649             : 
    4650       11155 :         do_end_loop(as_token->u.opline_num, 1 TSRMLS_CC);
    4651             : 
    4652       11155 :         zend_stack_top(&CG(foreach_copy_stack), (void **) &container_ptr);
    4653       11155 :         generate_free_foreach_copy(container_ptr TSRMLS_CC);
    4654       11155 :         zend_stack_del_top(&CG(foreach_copy_stack));
    4655             : 
    4656       11155 :         DEC_BPC(CG(active_op_array));
    4657       11155 : }
    4658             : /* }}} */
    4659             : 
    4660          11 : void zend_do_declare_begin(TSRMLS_D) /* {{{ */
    4661             : {
    4662          11 :         zend_stack_push(&CG(declare_stack), &CG(declarables), sizeof(zend_declarables));
    4663          11 : }
    4664             : /* }}} */
    4665             : 
    4666          11 : void zend_do_declare_stmt(znode *var, znode *val TSRMLS_DC) /* {{{ */
    4667             : {
    4668          11 :         if (!zend_binary_strcasecmp(var->u.constant.value.str.val, var->u.constant.value.str.len, "ticks", sizeof("ticks")-1)) {
    4669           5 :                 convert_to_long(&val->u.constant);
    4670           5 :                 CG(declarables).ticks = val->u.constant;
    4671             : #ifdef ZEND_MULTIBYTE
    4672             :         } else if (!zend_binary_strcasecmp(var->u.constant.value.str.val, var->u.constant.value.str.len, "encoding", sizeof("encoding")-1)) {
    4673             :                 zend_encoding *new_encoding, *old_encoding;
    4674             :                 zend_encoding_filter old_input_filter;
    4675             : 
    4676             :                 if ((Z_TYPE(val->u.constant) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
    4677             :                         zend_error(E_COMPILE_ERROR, "Cannot use constants as encoding");
    4678             :                 }
    4679             : 
    4680             :                 /*
    4681             :                  * Check that the pragma comes before any opcodes. If the compilation
    4682             :                  * got as far as this, the previous portion of the script must have been
    4683             :                  * parseable according to the .ini script_encoding setting. We still
    4684             :                  * want to tell them to put declare() at the top.
    4685             :                  */
    4686             :                 {
    4687             :                         int num = CG(active_op_array)->last;
    4688             :                         /* ignore ZEND_EXT_STMT and ZEND_TICKS */
    4689             :                         while (num > 0 &&
    4690             :                                                  (CG(active_op_array)->opcodes[num-1].opcode == ZEND_EXT_STMT ||
    4691             :                                                         CG(active_op_array)->opcodes[num-1].opcode == ZEND_TICKS)) {
    4692             :                                 --num;
    4693             :                         }
    4694             : 
    4695             :                         if (num > 0) {
    4696             :                                 zend_error(E_COMPILE_ERROR, "Encoding declaration pragma must be the very first statement in the script");
    4697             :                         }
    4698             :                 }
    4699             :                 CG(encoding_declared) = 1;
    4700             : 
    4701             :                 convert_to_string(&val->u.constant);
    4702             :                 new_encoding = zend_multibyte_fetch_encoding(val->u.constant.value.str.val);
    4703             :                 if (!new_encoding) {
    4704             :                         zend_error(E_COMPILE_WARNING, "Unsupported encoding [%s]", val->u.constant.value.str.val);
    4705             :                 } else {
    4706             :                         old_input_filter = LANG_SCNG(input_filter);
    4707             :                         old_encoding = LANG_SCNG(script_encoding);
    4708             :                         zend_multibyte_set_filter(new_encoding TSRMLS_CC);
    4709             : 
    4710             :                         /* need to re-scan if input filter changed */
    4711             :                         if (old_input_filter != LANG_SCNG(input_filter) ||
    4712             :                                 ((old_input_filter == zend_multibyte_script_encoding_filter) &&
    4713             :                                  (new_encoding != old_encoding))) {
    4714             :                                 zend_multibyte_yyinput_again(old_input_filter, old_encoding TSRMLS_CC);
    4715             :                         }
    4716             :                 }
    4717             :                 efree(val->u.constant.value.str.val);
    4718             : #else  /* !ZEND_MULTIBYTE */
    4719           6 :         } else if (!zend_binary_strcasecmp(var->u.constant.value.str.val, var->u.constant.value.str.len, "encoding", sizeof("encoding")-1)) {
    4720             :                 /* Do not generate any kind of warning for encoding declares */
    4721             :                 /* zend_error(E_COMPILE_WARNING, "Declare encoding [%s] not supported", val->u.constant.value.str.val); */
    4722           6 :                 zval_dtor(&val->u.constant);
    4723             : #endif /* ZEND_MULTIBYTE */
    4724             :         } else {
    4725           0 :                 zend_error(E_COMPILE_WARNING, "Unsupported declare '%s'", var->u.constant.value.str.val);
    4726           0 :                 zval_dtor(&val->u.constant);
    4727             :         }
    4728          11 :         zval_dtor(&var->u.constant);
    4729          11 : }
    4730             : /* }}} */
    4731             : 
    4732          11 : void zend_do_declare_end(const znode *declare_token TSRMLS_DC) /* {{{ */
    4733             : {
    4734             :         zend_declarables *declarables;
    4735             : 
    4736          11 :         zend_stack_top(&CG(declare_stack), (void **) &declarables);
    4737             :         /* We should restore if there was more than (current - start) - (ticks?1:0) opcodes */
    4738          11 :         if ((get_next_op_number(CG(active_op_array)) - declare_token->u.opline_num) - ((Z_LVAL(CG(declarables).ticks))?1:0)) {
    4739           1 :                 CG(declarables) = *declarables;
    4740             :         }
    4741          11 : }
    4742             : /* }}} */
    4743             : 
    4744       14605 : void zend_do_exit(znode *result, const znode *message TSRMLS_DC) /* {{{ */
    4745             : {
    4746       14605 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4747             : 
    4748       14605 :         opline->opcode = ZEND_EXIT;
    4749       14605 :         opline->op1 = *message;
    4750       14605 :         SET_UNUSED(opline->op2);
    4751             : 
    4752       14605 :         result->op_type = IS_CONST;
    4753       14605 :         Z_TYPE(result->u.constant) = IS_BOOL;
    4754       14605 :         Z_LVAL(result->u.constant) = 1;
    4755       14605 : }
    4756             : /* }}} */
    4757             : 
    4758        6683 : void zend_do_begin_silence(znode *strudel_token TSRMLS_DC) /* {{{ */
    4759             : {
    4760        6683 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4761             : 
    4762        6683 :         opline->opcode = ZEND_BEGIN_SILENCE;
    4763        6683 :         opline->result.op_type = IS_TMP_VAR;
    4764        6683 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    4765        6683 :         SET_UNUSED(opline->op1);
    4766        6683 :         SET_UNUSED(opline->op2);
    4767        6683 :         *strudel_token = opline->result;
    4768        6683 : }
    4769             : /* }}} */
    4770             : 
    4771        6683 : void zend_do_end_silence(const znode *strudel_token TSRMLS_DC) /* {{{ */
    4772             : {
    4773        6683 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4774             : 
    4775        6683 :         opline->opcode = ZEND_END_SILENCE;
    4776        6683 :         opline->op1 = *strudel_token;
    4777        6683 :         SET_UNUSED(opline->op2);
    4778        6683 : }
    4779             : /* }}} */
    4780             : 
    4781           8 : void zend_do_jmp_set(const znode *value, znode *jmp_token, znode *colon_token TSRMLS_DC) /* {{{ */
    4782             : {
    4783           8 :         int op_number = get_next_op_number(CG(active_op_array));
    4784           8 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4785             : 
    4786           8 :         opline->opcode = ZEND_JMP_SET;
    4787           8 :         opline->result.op_type = IS_TMP_VAR;
    4788           8 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    4789           8 :         opline->op1 = *value;
    4790           8 :         SET_UNUSED(opline->op2);
    4791             :         
    4792           8 :         *colon_token = opline->result;
    4793             : 
    4794           8 :         jmp_token->u.opline_num = op_number;
    4795             : 
    4796           8 :         INC_BPC(CG(active_op_array));
    4797           8 : }
    4798             : /* }}} */
    4799             : 
    4800           8 : void zend_do_jmp_set_else(znode *result, const znode *false_value, const znode *jmp_token, const znode *colon_token TSRMLS_DC) /* {{{ */
    4801             : {
    4802           8 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4803             : 
    4804           8 :         opline->opcode = ZEND_QM_ASSIGN;
    4805           8 :         opline->extended_value = 0;
    4806           8 :         opline->result = *colon_token;
    4807           8 :         opline->op1 = *false_value;
    4808           8 :         SET_UNUSED(opline->op2);
    4809             :         
    4810           8 :         *result = opline->result;
    4811             : 
    4812           8 :         CG(active_op_array)->opcodes[jmp_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array));
    4813             :         
    4814           8 :         DEC_BPC(CG(active_op_array));
    4815           8 : }
    4816             : /* }}} */
    4817             : 
    4818       25785 : void zend_do_begin_qm_op(const znode *cond, znode *qm_token TSRMLS_DC) /* {{{ */
    4819             : {
    4820       25785 :         int jmpz_op_number = get_next_op_number(CG(active_op_array));
    4821             :         zend_op *opline;
    4822             : 
    4823       25785 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4824             : 
    4825       25785 :         opline->opcode = ZEND_JMPZ;
    4826       25785 :         opline->op1 = *cond;
    4827       25785 :         SET_UNUSED(opline->op2);
    4828       25785 :         opline->op2.u.opline_num = jmpz_op_number;
    4829       25785 :         *qm_token = opline->op2;
    4830             : 
    4831       25785 :         INC_BPC(CG(active_op_array));
    4832       25785 : }
    4833             : /* }}} */
    4834             : 
    4835       25785 : void zend_do_qm_true(const znode *true_value, znode *qm_token, znode *colon_token TSRMLS_DC) /* {{{ */
    4836             : {
    4837       25785 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4838             : 
    4839       25785 :         CG(active_op_array)->opcodes[qm_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array))+1; /* jmp over the ZEND_JMP */
    4840             : 
    4841       25785 :         opline->opcode = ZEND_QM_ASSIGN;
    4842       25785 :         opline->result.op_type = IS_TMP_VAR;
    4843       25785 :         opline->result.u.var = get_temporary_variable(CG(active_op_array));
    4844       25785 :         opline->op1 = *true_value;
    4845       25785 :         SET_UNUSED(opline->op2);
    4846             : 
    4847       25785 :         *qm_token = opline->result;
    4848       25785 :         colon_token->u.opline_num = get_next_op_number(CG(active_op_array));
    4849             : 
    4850       25785 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4851       25785 :         opline->opcode = ZEND_JMP;
    4852       25785 :         SET_UNUSED(opline->op1);
    4853       25785 :         SET_UNUSED(opline->op2);
    4854       25785 : }
    4855             : /* }}} */
    4856             : 
    4857       25785 : void zend_do_qm_false(znode *result, const znode *false_value, const znode *qm_token, const znode *colon_token TSRMLS_DC) /* {{{ */
    4858             : {
    4859       25785 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4860             : 
    4861       25785 :         opline->opcode = ZEND_QM_ASSIGN;
    4862       25785 :         opline->result = *qm_token;
    4863       25785 :         opline->op1 = *false_value;
    4864       25785 :         SET_UNUSED(opline->op2);
    4865             : 
    4866       25785 :         CG(active_op_array)->opcodes[colon_token->u.opline_num].op1.u.opline_num = get_next_op_number(CG(active_op_array));
    4867             : 
    4868       25785 :         *result = opline->result;
    4869             : 
    4870       25785 :         DEC_BPC(CG(active_op_array));
    4871       25785 : }
    4872             : /* }}} */
    4873             : 
    4874      544700 : void zend_do_extended_info(TSRMLS_D) /* {{{ */
    4875             : {
    4876             :         zend_op *opline;
    4877             : 
    4878      544700 :         if (!(CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO)) {
    4879      544700 :                 return;
    4880             :         }
    4881             : 
    4882           0 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4883             : 
    4884           0 :         opline->opcode = ZEND_EXT_STMT;
    4885           0 :         SET_UNUSED(opline->op1);
    4886           0 :         SET_UNUSED(opline->op2);
    4887             : }
    4888             : /* }}} */
    4889             : 
    4890      383737 : void zend_do_extended_fcall_begin(TSRMLS_D) /* {{{ */
    4891             : {
    4892             :         zend_op *opline;
    4893             : 
    4894      383737 :         if (!(CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO)) {
    4895      383737 :                 return;
    4896             :         }
    4897             : 
    4898           0 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4899             : 
    4900           0 :         opline->opcode = ZEND_EXT_FCALL_BEGIN;
    4901           0 :         SET_UNUSED(opline->op1);
    4902           0 :         SET_UNUSED(opline->op2);
    4903             : }
    4904             : /* }}} */
    4905             : 
    4906      383724 : void zend_do_extended_fcall_end(TSRMLS_D) /* {{{ */
    4907             : {
    4908             :         zend_op *opline;
    4909             : 
    4910      383724 :         if (!(CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO)) {
    4911      383724 :                 return;
    4912             :         }
    4913             : 
    4914           0 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4915             : 
    4916           0 :         opline->opcode = ZEND_EXT_FCALL_END;
    4917           0 :         SET_UNUSED(opline->op1);
    4918           0 :         SET_UNUSED(opline->op2);
    4919             : }
    4920             : /* }}} */
    4921             : 
    4922          33 : void zend_do_ticks(TSRMLS_D) /* {{{ */
    4923             : {
    4924          33 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4925             : 
    4926          33 :         opline->opcode = ZEND_TICKS;
    4927          33 :         opline->op1.u.constant = CG(declarables).ticks;
    4928          33 :         opline->op1.op_type = IS_CONST;
    4929          33 :         SET_UNUSED(opline->op2);
    4930          33 : }
    4931             : /* }}} */
    4932             : 
    4933      174384 : void zend_auto_global_dtor(zend_auto_global *auto_global) /* {{{ */
    4934             : {
    4935      174384 :         free(auto_global->name);
    4936      174384 : }
    4937             : /* }}} */
    4938             : 
    4939      914640 : zend_bool zend_is_auto_global(const char *name, uint name_len TSRMLS_DC) /* {{{ */
    4940             : {
    4941             :         zend_auto_global *auto_global;
    4942             : 
    4943      914640 :         if (zend_hash_find(CG(auto_globals), name, name_len+1, (void **) &auto_global)==SUCCESS) {
    4944       55029 :                 if (auto_global->armed) {
    4945           3 :                         auto_global->armed = auto_global->auto_global_callback(auto_global->name, auto_global->name_len TSRMLS_CC);
    4946             :                 }
    4947       55029 :                 return 1;
    4948             :         }
    4949      859611 :         return 0;
    4950             : }
    4951             : /* }}} */
    4952             : 
    4953      174069 : int zend_register_auto_global(const char *name, uint name_len, zend_auto_global_callback auto_global_callback TSRMLS_DC) /* {{{ */
    4954             : {
    4955             :         zend_auto_global auto_global;
    4956             : 
    4957      174069 :         auto_global.name = zend_strndup(name, name_len);
    4958      174069 :         auto_global.name_len = name_len;
    4959      174069 :         auto_global.auto_global_callback = auto_global_callback;
    4960             : 
    4961      174069 :         return zend_hash_add(CG(auto_globals), name, name_len+1, &auto_global, sizeof(zend_auto_global), NULL);
    4962             : }
    4963             : /* }}} */
    4964             : 
    4965     5796655 : int zendlex(znode *zendlval TSRMLS_DC) /* {{{ */
    4966             : {
    4967             :         int retval;
    4968             : 
    4969     5796655 :         if (CG(increment_lineno)) {
    4970       24208 :                 CG(zend_lineno)++;
    4971       24208 :                 CG(increment_lineno) = 0;
    4972             :         }
    4973             : 
    4974             : again:
    4975     8294711 :         Z_TYPE(zendlval->u.constant) = IS_LONG;
    4976     8294711 :         retval = lex_scan(&zendlval->u.constant TSRMLS_CC);
    4977     8294711 :         switch (retval) {
    4978             :                 case T_COMMENT:
    4979             :                 case T_DOC_COMMENT:
    4980             :                 case T_OPEN_TAG:
    4981             :                 case T_WHITESPACE:
    4982     2498053 :                         goto again;
    4983             : 
    4984             :                 case T_CLOSE_TAG:
    4985       27582 :                         if (LANG_SCNG(yy_text)[LANG_SCNG(yy_leng)-1] != '>') {
    4986       22857 :                                 CG(increment_lineno) = 1;
    4987             :                         }
    4988       27582 :                         if (CG(has_bracketed_namespaces) && !CG(in_namespace)) {
    4989           3 :                                 goto again;                             
    4990             :                         }
    4991       27579 :                         retval = ';'; /* implicit ; */
    4992       27579 :                         break;
    4993             :                 case T_OPEN_TAG_WITH_ECHO:
    4994           4 :                         retval = T_ECHO;
    4995           4 :                         break;
    4996             :                 case T_END_HEREDOC:
    4997        1415 :                         efree(Z_STRVAL(zendlval->u.constant));
    4998             :                         break;
    4999             :         }
    5000             : 
    5001     5796655 :         INIT_PZVAL(&zendlval->u.constant);
    5002     5796655 :         zendlval->op_type = IS_CONST;
    5003     5796655 :         return retval;
    5004             : }
    5005             : /* }}} */
    5006             : 
    5007     3062564 : ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers TSRMLS_DC) /* {{{ */
    5008             : {
    5009     3062564 :         zend_bool persistent_hashes = (ce->type == ZEND_INTERNAL_CLASS) ? 1 : 0;
    5010     3062564 :         dtor_func_t zval_ptr_dtor_func = ((persistent_hashes) ? ZVAL_INTERNAL_PTR_DTOR : ZVAL_PTR_DTOR);
    5011             : 
    5012     3062564 :         ce->refcount = 1;
    5013     3062564 :         ce->constants_updated = 0;
    5014     3062564 :         ce->ce_flags = 0;
    5015             : 
    5016     3062564 :         ce->doc_comment = NULL;
    5017     3062564 :         ce->doc_comment_len = 0;
    5018             : 
    5019     3062564 :         zend_hash_init_ex(&ce->default_properties, 0, NULL, zval_ptr_dtor_func, persistent_hashes, 0);
    5020     3062564 :         zend_hash_init_ex(&ce->properties_info, 0, NULL, (dtor_func_t) (persistent_hashes ? zend_destroy_property_info_internal : zend_destroy_property_info), persistent_hashes, 0);
    5021     3062564 :         zend_hash_init_ex(&ce->default_static_members, 0, NULL, zval_ptr_dtor_func, persistent_hashes, 0);
    5022     3062564 :         zend_hash_init_ex(&ce->constants_table, 0, NULL, zval_ptr_dtor_func, persistent_hashes, 0);
    5023     3062564 :         zend_hash_init_ex(&ce->function_table, 0, NULL, ZEND_FUNCTION_DTOR, persistent_hashes, 0);
    5024             : 
    5025     3062564 :         if (ce->type == ZEND_INTERNAL_CLASS) {
    5026             : #ifdef ZTS
    5027             :                 int n = zend_hash_num_elements(CG(class_table));
    5028             : 
    5029             :                 if (CG(static_members) && n >= CG(last_static_member)) {
    5030             :                         /* Support for run-time declaration: dl() */
    5031             :                         CG(last_static_member) = n+1;
    5032             :                         CG(static_members) = realloc(CG(static_members), (n+1)*sizeof(HashTable*));
    5033             :                         CG(static_members)[n] = NULL;
    5034             :                 }
    5035             :                 ce->static_members = (HashTable*)(zend_intptr_t)n;
    5036             : #else
    5037     3055878 :                 ce->static_members = NULL;
    5038             : #endif
    5039             :         } else {
    5040        6686 :                 ce->static_members = &ce->default_static_members;
    5041             :         }
    5042             : 
    5043     3062564 :         if (nullify_handlers) {
    5044        6686 :                 ce->constructor = NULL;
    5045        6686 :                 ce->destructor = NULL;
    5046        6686 :                 ce->clone = NULL;
    5047        6686 :                 ce->__get = NULL;
    5048        6686 :                 ce->__set = NULL;
    5049        6686 :                 ce->__unset = NULL;
    5050        6686 :                 ce->__isset = NULL;
    5051        6686 :                 ce->__call = NULL;
    5052        6686 :                 ce->__callstatic = NULL;
    5053        6686 :                 ce->__tostring = NULL;
    5054        6686 :                 ce->create_object = NULL;
    5055        6686 :                 ce->get_iterator = NULL;
    5056        6686 :                 ce->iterator_funcs.funcs = NULL;
    5057        6686 :                 ce->interface_gets_implemented = NULL;
    5058        6686 :                 ce->get_static_method = NULL;
    5059        6686 :                 ce->parent = NULL;
    5060        6686 :                 ce->num_interfaces = 0;
    5061        6686 :                 ce->interfaces = NULL;
    5062        6686 :                 ce->module = NULL;
    5063        6686 :                 ce->serialize = NULL;
    5064        6686 :                 ce->unserialize = NULL;
    5065        6686 :                 ce->serialize_func = NULL;
    5066        6686 :                 ce->unserialize_func = NULL;
    5067        6686 :                 ce->builtin_functions = NULL;
    5068             :         }
    5069     3062564 : }
    5070             : /* }}} */
    5071             : 
    5072      132231 : int zend_get_class_fetch_type(const char *class_name, uint class_name_len) /* {{{ */
    5073             : {
    5074      227618 :         if ((class_name_len == sizeof("self")-1) &&
    5075       95387 :                 !memcmp(class_name, "self", sizeof("self")-1)) {
    5076        6413 :                 return ZEND_FETCH_CLASS_SELF;           
    5077      132895 :         } else if ((class_name_len == sizeof("parent")-1) &&
    5078        7077 :                 !memcmp(class_name, "parent", sizeof("parent")-1)) {
    5079        4209 :                 return ZEND_FETCH_CLASS_PARENT;
    5080      124477 :         } else if ((class_name_len == sizeof("static")-1) &&
    5081        2868 :                 !memcmp(class_name, "static", sizeof("static")-1)) {
    5082          64 :                 return ZEND_FETCH_CLASS_STATIC;
    5083             :         } else {
    5084      121545 :                 return ZEND_FETCH_CLASS_DEFAULT;
    5085             :         }
    5086             : }
    5087             : /* }}} */
    5088             : 
    5089           0 : ZEND_API char* zend_get_compiled_variable_name(const zend_op_array *op_array, zend_uint var, int* name_len) /* {{{ */
    5090             : {
    5091           0 :         if (name_len) {
    5092           0 :                 *name_len = op_array->vars[var].name_len;
    5093             :         }
    5094           0 :         return op_array->vars[var].name;
    5095             : }
    5096             : /* }}} */
    5097             : 
    5098         704 : void zend_do_build_namespace_name(znode *result, znode *prefix, znode *name TSRMLS_DC) /* {{{ */
    5099             : {
    5100         704 :         if (prefix) {
    5101         677 :                 *result = *prefix;
    5102        1354 :                 if (Z_TYPE(result->u.constant) == IS_STRING &&
    5103         677 :                 Z_STRLEN(result->u.constant) == 0) {
    5104             :                         /* namespace\ */
    5105          48 :                         if (CG(current_namespace)) {
    5106             :                                 znode tmp;
    5107             : 
    5108          27 :                                 zval_dtor(&result->u.constant);
    5109          27 :                                 tmp.op_type = IS_CONST;
    5110          27 :                                 tmp.u.constant = *CG(current_namespace);
    5111          27 :                                 zval_copy_ctor(&tmp.u.constant);
    5112          27 :                                 zend_do_build_namespace_name(result, NULL, &tmp TSRMLS_CC);
    5113             :                         }
    5114             :                 }
    5115             :         } else {
    5116          27 :                 result->op_type = IS_CONST;
    5117          27 :                 Z_TYPE(result->u.constant) = IS_STRING;
    5118          27 :                 Z_STRVAL(result->u.constant) = NULL;
    5119          27 :                 Z_STRLEN(result->u.constant) = 0;
    5120             :         }
    5121             :         /* prefix = result */
    5122         704 :         zend_do_build_full_name(NULL, result, name, 0 TSRMLS_CC);
    5123         704 : }
    5124             : /* }}} */
    5125             : 
    5126         142 : void zend_do_begin_namespace(const znode *name, zend_bool with_bracket TSRMLS_DC) /* {{{ */
    5127             : {
    5128             :         char *lcname;
    5129             : 
    5130             :         /* handle mixed syntax declaration or nested namespaces */
    5131         142 :         if (!CG(has_bracketed_namespaces)) {
    5132         136 :                 if (CG(current_namespace)) {
    5133             :                         /* previous namespace declarations were unbracketed */
    5134           7 :                         if (with_bracket) {
    5135           1 :                                 zend_error(E_COMPILE_ERROR, "Cannot mix bracketed namespace declarations with unbracketed namespace declarations");
    5136             :                         }
    5137             :                 }
    5138             :         } else {
    5139             :                 /* previous namespace declarations were bracketed */
    5140           6 :                 if (!with_bracket) {
    5141           1 :                         zend_error(E_COMPILE_ERROR, "Cannot mix bracketed namespace declarations with unbracketed namespace declarations");
    5142           5 :                 } else if (CG(current_namespace) || CG(in_namespace)) {
    5143           1 :                         zend_error(E_COMPILE_ERROR, "Namespace declarations cannot be nested");
    5144             :                 }
    5145             :         }
    5146             : 
    5147         139 :         if (((!with_bracket && !CG(current_namespace)) || (with_bracket && !CG(has_bracketed_namespaces))) && CG(active_op_array)->last > 0) {
    5148             :                 /* ignore ZEND_EXT_STMT and ZEND_TICKS */
    5149           3 :                 int num = CG(active_op_array)->last;
    5150          16 :                 while (num > 0 &&
    5151           4 :                                          (CG(active_op_array)->opcodes[num-1].opcode == ZEND_EXT_STMT ||
    5152           4 :                                                 CG(active_op_array)->opcodes[num-1].opcode == ZEND_TICKS)) {
    5153           2 :                         --num;
    5154             :                 }
    5155           3 :                 if (num > 0) {
    5156           2 :                         zend_error(E_COMPILE_ERROR, "Namespace declaration statement has to be the very first statement in the script");
    5157             :                 }
    5158             :         }
    5159             : 
    5160         137 :         CG(in_namespace) = 1;
    5161         137 :         if (with_bracket) {
    5162          17 :                 CG(has_bracketed_namespaces) = 1;
    5163             :         }
    5164             : 
    5165         137 :         if (name) {
    5166         135 :                 lcname = zend_str_tolower_dup(Z_STRVAL(name->u.constant), Z_STRLEN(name->u.constant));
    5167         282 :                 if (((Z_STRLEN(name->u.constant) == sizeof("self")-1) &&
    5168          10 :                                         !memcmp(lcname, "self", sizeof("self")-1)) ||
    5169         135 :                                 ((Z_STRLEN(name->u.constant) == sizeof("parent")-1) &&
    5170           2 :                                                 !memcmp(lcname, "parent", sizeof("parent")-1))) {
    5171           0 :                         zend_error(E_COMPILE_ERROR, "Cannot use '%s' as namespace name", Z_STRVAL(name->u.constant));
    5172             :                 }
    5173         135 :                 efree(lcname);
    5174             : 
    5175         135 :                 if (CG(current_namespace)) {
    5176           6 :                         zval_dtor(CG(current_namespace));
    5177             :                 } else {
    5178         129 :                         ALLOC_ZVAL(CG(current_namespace));
    5179             :                 }
    5180         135 :                 *CG(current_namespace) = name->u.constant;
    5181             :         } else {
    5182           2 :                 if (CG(current_namespace)) {
    5183           0 :                         zval_dtor(CG(current_namespace));
    5184           0 :                         FREE_ZVAL(CG(current_namespace));
    5185           0 :                         CG(current_namespace) = NULL;
    5186             :                 }
    5187             :         }
    5188             : 
    5189         137 :         if (CG(current_import)) {
    5190           1 :                 zend_hash_destroy(CG(current_import));
    5191           1 :                 efree(CG(current_import));
    5192           1 :                 CG(current_import) = NULL;
    5193             :         }
    5194             : 
    5195         137 :         if (CG(doc_comment)) {
    5196           1 :                 efree(CG(doc_comment));
    5197           1 :                 CG(doc_comment) = NULL;
    5198           1 :                 CG(doc_comment_len) = 0;
    5199             :         }
    5200         137 : }
    5201             : /* }}} */
    5202             : 
    5203          46 : void zend_do_use(znode *ns_name, znode *new_name, int is_global TSRMLS_DC) /* {{{ */
    5204             : {
    5205             :         char *lcname;
    5206             :         zval *name, *ns, tmp;
    5207          46 :         zend_bool warn = 0;
    5208             :         zend_class_entry **pce;
    5209             : 
    5210          46 :         if (!CG(current_import)) {
    5211          35 :                 CG(current_import) = emalloc(sizeof(HashTable));
    5212          35 :                 zend_hash_init(CG(current_import), 0, NULL, ZVAL_PTR_DTOR, 0);
    5213             :         }
    5214             : 
    5215          46 :         ALLOC_ZVAL(ns);
    5216          46 :         *ns = ns_name->u.constant;
    5217          46 :         if (new_name) {
    5218          29 :                 name = &new_name->u.constant;
    5219             :         } else {
    5220             :                 char *p;
    5221             : 
    5222             :                 /* The form "use A\B" is eqivalent to "use A\B as B".
    5223             :                    So we extract the last part of compound name to use as a new_name */
    5224          17 :                 name = &tmp;
    5225          17 :                 p = zend_memrchr(Z_STRVAL_P(ns), '\\', Z_STRLEN_P(ns));
    5226          17 :                 if (p) {
    5227           7 :                         ZVAL_STRING(name, p+1, 1);
    5228             :                 } else {
    5229          10 :                         *name = *ns;
    5230          10 :                         zval_copy_ctor(name);
    5231          10 :                         warn = !is_global && !CG(current_namespace);
    5232             :                 }
    5233             :         }
    5234             : 
    5235          46 :         lcname = zend_str_tolower_dup(Z_STRVAL_P(name), Z_STRLEN_P(name));
    5236             : 
    5237          99 :         if (((Z_STRLEN_P(name) == sizeof("self")-1) &&
    5238           7 :                                 !memcmp(lcname, "self", sizeof("self")-1)) ||
    5239          46 :                         ((Z_STRLEN_P(name) == sizeof("parent")-1) &&
    5240           0 :                                 !memcmp(lcname, "parent", sizeof("parent")-1))) {
    5241           0 :                 zend_error(E_COMPILE_ERROR, "Cannot use %s as %s because '%s' is a special class name", Z_STRVAL_P(ns), Z_STRVAL_P(name), Z_STRVAL_P(name));
    5242             :         }
    5243             : 
    5244          46 :         if (CG(current_namespace)) {
    5245             :                 /* Prefix import name with current namespace name to avoid conflicts with classes */
    5246          36 :                 char *c_ns_name = emalloc(Z_STRLEN_P(CG(current_namespace)) + 1 + Z_STRLEN_P(name) + 1);
    5247             : 
    5248          36 :                 zend_str_tolower_copy(c_ns_name, Z_STRVAL_P(CG(current_namespace)), Z_STRLEN_P(CG(current_namespace)));
    5249          36 :                 c_ns_name[Z_STRLEN_P(CG(current_namespace))] = '\\';
    5250          36 :                 memcpy(c_ns_name+Z_STRLEN_P(CG(current_namespace))+1, lcname, Z_STRLEN_P(name)+1);
    5251          36 :                 if (zend_hash_exists(CG(class_table), c_ns_name, Z_STRLEN_P(CG(current_namespace)) + 1 + Z_STRLEN_P(name)+1)) {
    5252           2 :                         char *tmp2 = zend_str_tolower_dup(Z_STRVAL_P(ns), Z_STRLEN_P(ns));
    5253             : 
    5254           3 :                         if (Z_STRLEN_P(ns) != Z_STRLEN_P(CG(current_namespace)) + 1 + Z_STRLEN_P(name) ||
    5255           1 :                                 memcmp(tmp2, c_ns_name, Z_STRLEN_P(ns))) {
    5256           1 :                                 zend_error(E_COMPILE_ERROR, "Cannot use %s as %s because the name is already in use", Z_STRVAL_P(ns), Z_STRVAL_P(name));
    5257             :                         }
    5258           1 :                         efree(tmp2);
    5259             :                 }
    5260          35 :                 efree(c_ns_name);
    5261          15 :         } else if (zend_hash_find(CG(class_table), lcname, Z_STRLEN_P(name)+1, (void**)&pce) == SUCCESS &&
    5262           3 :                    (*pce)->type == ZEND_USER_CLASS &&
    5263           2 :                    (*pce)->filename == CG(compiled_filename)) {
    5264           1 :                 char *c_tmp = zend_str_tolower_dup(Z_STRVAL_P(ns), Z_STRLEN_P(ns));
    5265             : 
    5266           2 :                 if (Z_STRLEN_P(ns) != Z_STRLEN_P(name) ||
    5267           1 :                         memcmp(c_tmp, lcname, Z_STRLEN_P(ns))) {
    5268           1 :                         zend_error(E_COMPILE_ERROR, "Cannot use %s as %s because the name is already in use", Z_STRVAL_P(ns), Z_STRVAL_P(name));
    5269             :                 }
    5270           0 :                 efree(c_tmp);
    5271             :         }
    5272             : 
    5273          44 :         if (zend_hash_add(CG(current_import), lcname, Z_STRLEN_P(name)+1, &ns, sizeof(zval*), NULL) != SUCCESS) {
    5274           0 :                 zend_error(E_COMPILE_ERROR, "Cannot use %s as %s because the name is already in use", Z_STRVAL_P(ns), Z_STRVAL_P(name));
    5275             :         }
    5276          44 :         if (warn) {
    5277           1 :                 zend_error(E_WARNING, "The use statement with non-compound name '%s' has no effect", Z_STRVAL_P(name));
    5278             :         }
    5279          44 :         efree(lcname);
    5280          44 :         zval_dtor(name);
    5281          44 : }
    5282             : /* }}} */
    5283             : 
    5284          34 : void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC) /* {{{ */
    5285             : {
    5286             :         zend_op *opline;
    5287             : 
    5288          34 :         if(Z_TYPE(value->u.constant) == IS_CONSTANT_ARRAY) {
    5289           1 :                 zend_error(E_COMPILE_ERROR, "Arrays are not allowed as constants");
    5290             :         }
    5291             : 
    5292          33 :         if (zend_get_ct_const(&name->u.constant, 0 TSRMLS_CC)) {
    5293           1 :                 zend_error(E_COMPILE_ERROR, "Cannot redeclare constant '%s'", Z_STRVAL(name->u.constant));
    5294             :         }
    5295             : 
    5296          32 :         if (CG(current_namespace)) {
    5297             :                 /* Prefix constant name with name of current namespace, lowercased */
    5298             :                 znode tmp;
    5299             : 
    5300          25 :                 tmp.op_type = IS_CONST;
    5301          25 :                 tmp.u.constant = *CG(current_namespace);
    5302          25 :                 Z_STRVAL(tmp.u.constant) = zend_str_tolower_dup(Z_STRVAL(tmp.u.constant), Z_STRLEN(tmp.u.constant));
    5303          25 :                 zend_do_build_namespace_name(&tmp, &tmp, name TSRMLS_CC);
    5304          25 :                 *name = tmp;
    5305             :         }
    5306             : 
    5307          32 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    5308          32 :         opline->opcode = ZEND_DECLARE_CONST;
    5309          32 :         SET_UNUSED(opline->result);
    5310          32 :         opline->op1 = *name;
    5311          32 :         opline->op2 = *value;
    5312          32 : }
    5313             : /* }}} */
    5314             : 
    5315      215795 : void zend_verify_namespace(TSRMLS_D) /* {{{ */
    5316             : {
    5317      215795 :         if (CG(has_bracketed_namespaces) && !CG(in_namespace)) {
    5318           1 :                 zend_error(E_COMPILE_ERROR, "No code may exist outside of namespace {}");
    5319             :         }
    5320      215794 : }
    5321             : /* }}} */
    5322             : 
    5323       29132 : void zend_do_end_namespace(TSRMLS_D) /* {{{ */
    5324             : {
    5325       29132 :         CG(in_namespace) = 0;
    5326       29132 :         if (CG(current_namespace)) {
    5327         120 :                 zval_dtor(CG(current_namespace));
    5328         120 :                 FREE_ZVAL(CG(current_namespace));
    5329         120 :                 CG(current_namespace) = NULL;
    5330             :         }
    5331       29132 :         if (CG(current_import)) {
    5332          29 :                 zend_hash_destroy(CG(current_import));
    5333          29 :                 efree(CG(current_import));
    5334          29 :                 CG(current_import) = NULL;
    5335             :         }
    5336             :         
    5337       29132 :         if (CG(doc_comment)) {
    5338          17 :                 efree(CG(doc_comment));
    5339          17 :                 CG(doc_comment) = NULL;
    5340          17 :                 CG(doc_comment_len) = 0;
    5341             :         }
    5342       29132 : }
    5343             : /* }}} */
    5344             : 
    5345       29118 : void zend_do_end_compilation(TSRMLS_D) /* {{{ */
    5346             : {
    5347       29118 :         CG(has_bracketed_namespaces) = 0;
    5348       29118 :         zend_do_end_namespace(TSRMLS_C);
    5349       29118 : }
    5350             : /* }}} */
    5351             : 
    5352             : /* {{{ zend_dirname
    5353             :    Returns directory name component of path */
    5354       24590 : ZEND_API size_t zend_dirname(char *path, size_t len)
    5355             : {
    5356       24590 :         register char *end = path + len - 1;
    5357       24590 :         unsigned int len_adjust = 0;
    5358             : 
    5359             : #ifdef PHP_WIN32
    5360             :         /* Note that on Win32 CWD is per drive (heritage from CP/M).
    5361             :          * This means dirname("c:foo") maps to "c:." or "c:" - which means CWD on C: drive.
    5362             :          */
    5363             :         if ((2 <= len) && isalpha((int)((unsigned char *)path)[0]) && (':' == path[1])) {
    5364             :                 /* Skip over the drive spec (if any) so as not to change */
    5365             :                 path += 2;
    5366             :                 len_adjust += 2;
    5367             :                 if (2 == len) {
    5368             :                         /* Return "c:" on Win32 for dirname("c:").
    5369             :                          * It would be more consistent to return "c:." 
    5370             :                          * but that would require making the string *longer*.
    5371             :                          */
    5372             :                         return len;
    5373             :                 }
    5374             :         }
    5375             : #elif defined(NETWARE)
    5376             :         /*
    5377             :          * Find the first occurence of : from the left 
    5378             :          * move the path pointer to the position just after :
    5379             :          * increment the len_adjust to the length of path till colon character(inclusive)
    5380             :          * If there is no character beyond : simple return len
    5381             :          */
    5382             :         char *colonpos = NULL;
    5383             :         colonpos = strchr(path, ':');
    5384             :         if (colonpos != NULL) {
    5385             :                 len_adjust = ((colonpos - path) + 1);
    5386             :                 path += len_adjust;
    5387             :                 if (len_adjust == len) {
    5388             :                         return len;
    5389             :                 }
    5390             :         }
    5391             : #endif
    5392             : 
    5393       24590 :         if (len == 0) {
    5394             :                 /* Illegal use of this function */
    5395          36 :                 return 0;
    5396             :         }
    5397             : 
    5398             :         /* Strip trailing slashes */
    5399       49199 :         while (end >= path && IS_SLASH_P(end)) {
    5400          91 :                 end--;
    5401             :         }
    5402       24554 :         if (end < path) {
    5403             :                 /* The path only contained slashes */
    5404          11 :                 path[0] = DEFAULT_SLASH;
    5405          11 :                 path[1] = '\0';
    5406          11 :                 return 1 + len_adjust;
    5407             :         }
    5408             : 
    5409             :         /* Strip filename */
    5410      548216 :         while (end >= path && !IS_SLASH_P(end)) {
    5411      499130 :                 end--;
    5412             :         }
    5413       24543 :         if (end < path) {
    5414             :                 /* No slash found, therefore return '.' */
    5415             : #ifdef NETWARE
    5416             :                 if (len_adjust == 0) {
    5417             :                         path[0] = '.';
    5418             :                         path[1] = '\0';
    5419             :                         return 1; /* only one character */
    5420             :                 } else {
    5421             :                         path[0] = '\0';
    5422             :                         return len_adjust;
    5423             :                 }
    5424             : #else
    5425         173 :                 path[0] = '.';
    5426         173 :                 path[1] = '\0';
    5427         173 :                 return 1 + len_adjust;
    5428             : #endif
    5429             :         }
    5430             : 
    5431             :         /* Strip slashes which came before the file name */
    5432       73125 :         while (end >= path && IS_SLASH_P(end)) {
    5433       24385 :                 end--;
    5434             :         }
    5435       24370 :         if (end < path) {
    5436          23 :                 path[0] = DEFAULT_SLASH;
    5437          23 :                 path[1] = '\0';
    5438          23 :                 return 1 + len_adjust;
    5439             :         }
    5440       24347 :         *(end+1) = '\0';
    5441             : 
    5442       24347 :         return (size_t)(end + 1 - path) + len_adjust;
    5443             : }
    5444             : /* }}} */
    5445             : 
    5446             : /*
    5447             :  * Local variables:
    5448             :  * tab-width: 4
    5449             :  * c-basic-offset: 4
    5450             :  * indent-tabs-mode: t
    5451             :  * End:
    5452             :  */

Generated by: LCOV version 1.10

Generated at Fri, 18 Apr 2014 07:01:23 +0000 (34 hours ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.