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: 4088 4288 95.3 %
Date: 2016-07-26 Functions: 260 263 98.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2016 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             :    |          Nikita Popov <nikic@php.net>                                |
      18             :    +----------------------------------------------------------------------+
      19             : */
      20             : 
      21             : /* $Id$ */
      22             : 
      23             : #include <zend_language_parser.h>
      24             : #include "zend.h"
      25             : #include "zend_compile.h"
      26             : #include "zend_constants.h"
      27             : #include "zend_llist.h"
      28             : #include "zend_API.h"
      29             : #include "zend_exceptions.h"
      30             : #include "zend_interfaces.h"
      31             : #include "zend_virtual_cwd.h"
      32             : #include "zend_multibyte.h"
      33             : #include "zend_language_scanner.h"
      34             : #include "zend_inheritance.h"
      35             : #include "zend_vm.h"
      36             : 
      37             : #define SET_NODE(target, src) do { \
      38             :                 target ## _type = (src)->op_type; \
      39             :                 if ((src)->op_type == IS_CONST) { \
      40             :                         target.constant = zend_add_literal(CG(active_op_array), &(src)->u.constant); \
      41             :                 } else { \
      42             :                         target = (src)->u.op; \
      43             :                 } \
      44             :         } while (0)
      45             : 
      46             : #define GET_NODE(target, src) do { \
      47             :                 (target)->op_type = src ## _type; \
      48             :                 if ((target)->op_type == IS_CONST) { \
      49             :                         ZVAL_COPY_VALUE(&(target)->u.constant, CT_CONSTANT(src)); \
      50             :                 } else { \
      51             :                         (target)->u.op = src; \
      52             :                 } \
      53             :         } while (0)
      54             : 
      55             : #define FC(member) (CG(file_context).member)
      56             : 
      57             : typedef struct _zend_loop_var {
      58             :         zend_uchar opcode;
      59             :         zend_uchar var_type;
      60             :         uint32_t   var_num;
      61             :         union {
      62             :                 uint32_t try_catch_offset;
      63             :                 uint32_t live_range_offset;
      64             :         } u;
      65             : } zend_loop_var;
      66             : 
      67      320833 : static inline void zend_alloc_cache_slot(uint32_t literal) {
      68      320833 :         zend_op_array *op_array = CG(active_op_array);
      69      320833 :         Z_CACHE_SLOT(op_array->literals[literal]) = op_array->cache_size;
      70      320833 :         op_array->cache_size += sizeof(void*);
      71      320833 : }
      72             : 
      73             : #define POLYMORPHIC_CACHE_SLOT_SIZE 2
      74             : 
      75       54919 : static inline void zend_alloc_polymorphic_cache_slot(uint32_t literal) {
      76       54919 :         zend_op_array *op_array = CG(active_op_array);
      77       54919 :         Z_CACHE_SLOT(op_array->literals[literal]) = op_array->cache_size;
      78       54919 :         op_array->cache_size += POLYMORPHIC_CACHE_SLOT_SIZE * sizeof(void*);
      79       54919 : }
      80             : 
      81             : ZEND_API zend_op_array *(*zend_compile_file)(zend_file_handle *file_handle, int type);
      82             : ZEND_API zend_op_array *(*zend_compile_string)(zval *source_string, char *filename);
      83             : 
      84             : #ifndef ZTS
      85             : ZEND_API zend_compiler_globals compiler_globals;
      86             : ZEND_API zend_executor_globals executor_globals;
      87             : #endif
      88             : 
      89             : static zend_op *zend_emit_op(znode *result, zend_uchar opcode, znode *op1, znode *op2);
      90             : 
      91     6623754 : static void zend_destroy_property_info_internal(zval *zv) /* {{{ */
      92             : {
      93     6623754 :         zend_property_info *property_info = Z_PTR_P(zv);
      94             : 
      95     6623754 :         zend_string_release(property_info->name);
      96     6623754 :         free(property_info);
      97     6623754 : }
      98             : /* }}} */
      99             : 
     100    27881443 : static void zend_destroy_class_constant_internal(zval *zv) /* {{{ */
     101             : {
     102    27881443 :         free(Z_PTR_P(zv));
     103    27881443 : }
     104             : /* }}} */
     105             : 
     106        3083 : static zend_string *zend_new_interned_string_safe(zend_string *str) /* {{{ */ {
     107             :         zend_string *interned_str;
     108             : 
     109             :         zend_string_addref(str);
     110        3083 :         interned_str = zend_new_interned_string(str);
     111        3083 :         if (str != interned_str) {
     112         761 :                 return interned_str;
     113             :         } else {
     114             :                 zend_string_release(str);
     115        2322 :                 return str;
     116             :         }
     117             : }
     118             : /* }}} */
     119             : 
     120       28893 : static zend_string *zend_build_runtime_definition_key(zend_string *name, unsigned char *lex_pos) /* {{{ */
     121             : {
     122             :         zend_string *result;
     123             :         char char_pos_buf[32];
     124       28893 :         size_t char_pos_len = zend_sprintf(char_pos_buf, "%p", lex_pos);
     125       28893 :         zend_string *filename = CG(active_op_array)->filename;
     126             : 
     127             :         /* NULL, name length, filename length, last accepting char position length */
     128       57786 :         result = zend_string_alloc(1 + ZSTR_LEN(name) + ZSTR_LEN(filename) + char_pos_len, 0);
     129       28893 :         sprintf(ZSTR_VAL(result), "%c%s%s%s", '\0', ZSTR_VAL(name), ZSTR_VAL(filename), char_pos_buf);
     130       28893 :         return zend_new_interned_string(result);
     131             : }
     132             : /* }}} */
     133             : 
     134       39495 : static zend_bool zend_get_unqualified_name(const zend_string *name, const char **result, size_t *result_len) /* {{{ */
     135             : {
     136       78990 :         const char *ns_separator = zend_memrchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name));
     137       39495 :         if (ns_separator != NULL) {
     138         596 :                 *result = ns_separator + 1;
     139         596 :                 *result_len = ZSTR_VAL(name) + ZSTR_LEN(name) - *result;
     140         596 :                 return 1;
     141             :         }
     142             : 
     143       38899 :         return 0;
     144             : }
     145             : /* }}} */
     146             : 
     147             : struct reserved_class_name {
     148             :         const char *name;
     149             :         size_t len;
     150             : };
     151             : static const struct reserved_class_name reserved_class_names[] = {
     152             :         {ZEND_STRL("bool")},
     153             :         {ZEND_STRL("false")},
     154             :         {ZEND_STRL("float")},
     155             :         {ZEND_STRL("int")},
     156             :         {ZEND_STRL("null")},
     157             :         {ZEND_STRL("parent")},
     158             :         {ZEND_STRL("self")},
     159             :         {ZEND_STRL("static")},
     160             :         {ZEND_STRL("string")},
     161             :         {ZEND_STRL("true")},
     162             :         {ZEND_STRL("void")},
     163             :         {ZEND_STRL("iterable")},
     164             :         {NULL, 0}
     165             : };
     166             : 
     167        8437 : static zend_bool zend_is_reserved_class_name(const zend_string *name) /* {{{ */
     168             : {
     169        8437 :         const struct reserved_class_name *reserved = reserved_class_names;
     170             : 
     171        8437 :         const char *uqname = ZSTR_VAL(name);
     172        8437 :         size_t uqname_len = ZSTR_LEN(name);
     173        8437 :         zend_get_unqualified_name(name, &uqname, &uqname_len);
     174             : 
     175      109533 :         for (; reserved->name; ++reserved) {
     176      107151 :                 if (uqname_len == reserved->len
     177      107151 :                         && zend_binary_strcasecmp(uqname, uqname_len, reserved->name, reserved->len) == 0
     178             :                 ) {
     179          18 :                         return 1;
     180             :                 }
     181             :         }
     182             : 
     183        8419 :         return 0;
     184             : }
     185             : /* }}} */
     186             : 
     187        8355 : ZEND_API void zend_assert_valid_class_name(const zend_string *name) /* {{{ */
     188             : {
     189        8355 :         if (zend_is_reserved_class_name(name)) {
     190          13 :                 zend_error_noreturn(E_COMPILE_ERROR,
     191             :                         "Cannot use '%s' as class name as it is reserved", ZSTR_VAL(name));
     192             :         }
     193        8342 : }
     194             : /* }}} */
     195             : 
     196             : typedef struct _builtin_type_info {
     197             :         const char* name;
     198             :         const size_t name_len;
     199             :         const zend_uchar type;
     200             : } builtin_type_info;
     201             : 
     202             : static const builtin_type_info builtin_types[] = {
     203             :         {ZEND_STRL("int"), IS_LONG},
     204             :         {ZEND_STRL("float"), IS_DOUBLE},
     205             :         {ZEND_STRL("string"), IS_STRING},
     206             :         {ZEND_STRL("bool"), _IS_BOOL},
     207             :         {ZEND_STRL("void"), IS_VOID},
     208             :         {ZEND_STRL("iterable"), IS_ITERABLE},
     209             :         {NULL, 0, IS_UNDEF}
     210             : };
     211             : 
     212             : 
     213             : static zend_always_inline zend_uchar zend_lookup_builtin_type_by_name(const zend_string *name) /* {{{ */
     214             : {
     215         465 :         const builtin_type_info *info = &builtin_types[0];
     216             : 
     217        1843 :         for (; info->name; ++info) {
     218        2453 :                 if (ZSTR_LEN(name) == info->name_len
     219        2453 :                         && zend_binary_strcasecmp(ZSTR_VAL(name), ZSTR_LEN(name), info->name, info->name_len) == 0
     220             :                 ) {
     221         207 :                         return info->type;
     222             :                 }
     223             :         }
     224             : 
     225         258 :         return 0;
     226             : }
     227             : /* }}} */
     228             : 
     229             : 
     230       74280 : void zend_oparray_context_begin(zend_oparray_context *prev_context) /* {{{ */
     231             : {
     232       74280 :         *prev_context = CG(context);
     233       74280 :         CG(context).opcodes_size = INITIAL_OP_ARRAY_SIZE;
     234       74280 :         CG(context).vars_size = 0;
     235       74280 :         CG(context).literals_size = 0;
     236       74280 :         CG(context).backpatch_count = 0;
     237       74280 :         CG(context).in_finally = 0;
     238       74280 :         CG(context).fast_call_var = -1;
     239       74280 :         CG(context).try_catch_offset = -1;
     240       74280 :         CG(context).current_brk_cont = -1;
     241       74280 :         CG(context).last_brk_cont = 0;
     242       74280 :         CG(context).brk_cont_array = NULL;
     243       74280 :         CG(context).labels = NULL;
     244       74280 : }
     245             : /* }}} */
     246             : 
     247       73927 : void zend_oparray_context_end(zend_oparray_context *prev_context) /* {{{ */
     248             : {
     249       73927 :         if (CG(context).brk_cont_array) {
     250       12471 :                 efree(CG(context).brk_cont_array);
     251       12471 :                 CG(context).brk_cont_array = NULL;
     252             :         }
     253       73927 :         if (CG(context).labels) {
     254          22 :                 zend_hash_destroy(CG(context).labels);
     255          22 :                 FREE_HASHTABLE(CG(context).labels);
     256          22 :                 CG(context).labels = NULL;
     257             :         }
     258       73927 :         CG(context) = *prev_context;
     259       73927 : }
     260             : /* }}} */
     261             : 
     262       34453 : static void zend_reset_import_tables(void) /* {{{ */
     263             : {
     264       34453 :         if (FC(imports)) {
     265          44 :                 zend_hash_destroy(FC(imports));
     266          44 :                 efree(FC(imports));
     267          44 :                 FC(imports) = NULL;
     268             :         }
     269             : 
     270       34453 :         if (FC(imports_function)) {
     271          15 :                 zend_hash_destroy(FC(imports_function));
     272          15 :                 efree(FC(imports_function));
     273          15 :                 FC(imports_function) = NULL;
     274             :         }
     275             : 
     276       34453 :         if (FC(imports_const)) {
     277          13 :                 zend_hash_destroy(FC(imports_const));
     278          13 :                 efree(FC(imports_const));
     279          13 :                 FC(imports_const) = NULL;
     280             :         }
     281       34453 : }
     282             : /* }}} */
     283             : 
     284       34196 : static void zend_end_namespace(void) /* {{{ */ {
     285       34196 :         FC(in_namespace) = 0;
     286       34196 :         zend_reset_import_tables();
     287       34196 :         if (FC(current_namespace)) {
     288         193 :                 zend_string_release(FC(current_namespace));
     289         193 :                 FC(current_namespace) = NULL;
     290             :         }
     291       34196 : }
     292             : /* }}} */
     293             : 
     294       34376 : void zend_file_context_begin(zend_file_context *prev_context) /* {{{ */
     295             : {
     296       34376 :         *prev_context = CG(file_context);
     297       34376 :         FC(imports) = NULL;
     298       34376 :         FC(imports_function) = NULL;
     299       34376 :         FC(imports_const) = NULL;
     300       34376 :         FC(current_namespace) = NULL;
     301       34376 :         FC(in_namespace) = 0;
     302       34376 :         FC(has_bracketed_namespaces) = 0;
     303       34376 :         FC(declarables).ticks = 0;
     304       34376 : }
     305             : /* }}} */
     306             : 
     307       34100 : void zend_file_context_end(zend_file_context *prev_context) /* {{{ */
     308             : {
     309       34100 :         zend_end_namespace();
     310       34100 :         CG(file_context) = *prev_context;
     311       34100 : }
     312             : /* }}} */
     313             : 
     314       23407 : void zend_init_compiler_data_structures(void) /* {{{ */
     315             : {
     316       23407 :         zend_stack_init(&CG(loop_var_stack), sizeof(zend_loop_var));
     317       23407 :         zend_stack_init(&CG(delayed_oplines_stack), sizeof(zend_op));
     318       23407 :         CG(active_class_entry) = NULL;
     319       23407 :         CG(in_compilation) = 0;
     320       23407 :         CG(start_lineno) = 0;
     321       23407 :         zend_hash_init(&CG(const_filenames), 8, NULL, NULL, 0);
     322             : 
     323       23407 :         CG(encoding_declared) = 0;
     324       23407 : }
     325             : /* }}} */
     326             : 
     327       33277 : ZEND_API void file_handle_dtor(zend_file_handle *fh) /* {{{ */
     328             : {
     329             : 
     330       33277 :         zend_file_handle_dtor(fh);
     331       33277 : }
     332             : /* }}} */
     333             : 
     334       23407 : void init_compiler(void) /* {{{ */
     335             : {
     336       23407 :         CG(arena) = zend_arena_create(64 * 1024);
     337       23407 :         CG(active_op_array) = NULL;
     338       23407 :         memset(&CG(context), 0, sizeof(CG(context)));
     339       23407 :         zend_init_compiler_data_structures();
     340       23407 :         zend_init_rsrc_list();
     341       23407 :         zend_hash_init(&CG(filenames_table), 8, NULL, ZVAL_PTR_DTOR, 0);
     342       23407 :         zend_llist_init(&CG(open_files), sizeof(zend_file_handle), (void (*)(void *)) file_handle_dtor, 0);
     343       23407 :         CG(unclean_shutdown) = 0;
     344       23407 : }
     345             : /* }}} */
     346             : 
     347       23445 : void shutdown_compiler(void) /* {{{ */
     348             : {
     349       23445 :         zend_stack_destroy(&CG(loop_var_stack));
     350       23445 :         zend_stack_destroy(&CG(delayed_oplines_stack));
     351       23445 :         zend_hash_destroy(&CG(filenames_table));
     352       23445 :         zend_hash_destroy(&CG(const_filenames));
     353       23445 :         zend_arena_destroy(CG(arena));
     354       23445 : }
     355             : /* }}} */
     356             : 
     357       34587 : ZEND_API zend_string *zend_set_compiled_filename(zend_string *new_compiled_filename) /* {{{ */
     358             : {
     359             :         zval *p, rv;
     360             : 
     361       34587 :         if ((p = zend_hash_find(&CG(filenames_table), new_compiled_filename))) {
     362             :                 ZEND_ASSERT(Z_TYPE_P(p) == IS_STRING);
     363         880 :                 CG(compiled_filename) = Z_STR_P(p);
     364         880 :                 return Z_STR_P(p);
     365             :         }
     366             : 
     367       33707 :         ZVAL_STR_COPY(&rv, new_compiled_filename);
     368       33707 :         zend_hash_update(&CG(filenames_table), new_compiled_filename, &rv);
     369             : 
     370       33707 :         CG(compiled_filename) = new_compiled_filename;
     371       33707 :         return new_compiled_filename;
     372             : }
     373             : /* }}} */
     374             : 
     375       34317 : ZEND_API void zend_restore_compiled_filename(zend_string *original_compiled_filename) /* {{{ */
     376             : {
     377       34317 :         CG(compiled_filename) = original_compiled_filename;
     378       34317 : }
     379             : /* }}} */
     380             : 
     381      118137 : ZEND_API zend_string *zend_get_compiled_filename(void) /* {{{ */
     382             : {
     383      118137 :         return CG(compiled_filename);
     384             : }
     385             : /* }}} */
     386             : 
     387         842 : ZEND_API int zend_get_compiled_lineno(void) /* {{{ */
     388             : {
     389         842 :         return CG(zend_lineno);
     390             : }
     391             : /* }}} */
     392             : 
     393      450154 : ZEND_API zend_bool zend_is_compiling(void) /* {{{ */
     394             : {
     395      450154 :         return CG(in_compilation);
     396             : }
     397             : /* }}} */
     398             : 
     399      977209 : static uint32_t get_temporary_variable(zend_op_array *op_array) /* {{{ */
     400             : {
     401      977209 :         return (uint32_t)op_array->T++;
     402             : }
     403             : /* }}} */
     404             : 
     405      771288 : static int lookup_cv(zend_op_array *op_array, zend_string* name) /* {{{ */{
     406      771288 :         int i = 0;
     407      771288 :         zend_ulong hash_value = zend_string_hash_val(name);
     408             : 
     409   138592204 :         while (i < op_array->last_var) {
     410   276246926 :                 if (ZSTR_VAL(op_array->vars[i]) == ZSTR_VAL(name) ||
     411   137586541 :                     (ZSTR_H(op_array->vars[i]) == hash_value &&
     412      536913 :                      ZSTR_LEN(op_array->vars[i]) == ZSTR_LEN(name) &&
     413      536913 :                      memcmp(ZSTR_VAL(op_array->vars[i]), ZSTR_VAL(name), ZSTR_LEN(name)) == 0)) {
     414             :                         zend_string_release(name);
     415      536931 :                         return (int)(zend_intptr_t)ZEND_CALL_VAR_NUM(NULL, i);
     416             :                 }
     417   137049628 :                 i++;
     418             :         }
     419      234357 :         i = op_array->last_var;
     420      234357 :         op_array->last_var++;
     421      234357 :         if (op_array->last_var > CG(context).vars_size) {
     422       55619 :                 CG(context).vars_size += 16; /* FIXME */
     423       55619 :                 op_array->vars = erealloc(op_array->vars, CG(context).vars_size * sizeof(zend_string*));
     424             :         }
     425             : 
     426      234357 :         op_array->vars[i] = zend_new_interned_string(name);
     427      234357 :         return (int)(zend_intptr_t)ZEND_CALL_VAR_NUM(NULL, i);
     428             : }
     429             : /* }}} */
     430             : 
     431       44543 : void zend_del_literal(zend_op_array *op_array, int n) /* {{{ */
     432             : {
     433       44543 :         zval_dtor(CT_CONSTANT_EX(op_array, n));
     434       44543 :         if (n + 1 == op_array->last_literal) {
     435       43414 :                 op_array->last_literal--;
     436             :         } else {
     437        1129 :                 ZVAL_UNDEF(CT_CONSTANT_EX(op_array, n));
     438             :         }
     439       44543 : }
     440             : /* }}} */
     441             : 
     442             : /* Common part of zend_add_literal and zend_append_individual_literal */
     443     1261866 : static inline void zend_insert_literal(zend_op_array *op_array, zval *zv, int literal_position) /* {{{ */
     444             : {
     445     1591340 :         if (Z_TYPE_P(zv) == IS_STRING || Z_TYPE_P(zv) == IS_CONSTANT) {
     446      932760 :                 zend_string_hash_val(Z_STR_P(zv));
     447      932760 :                 Z_STR_P(zv) = zend_new_interned_string(Z_STR_P(zv));
     448      932760 :                 if (ZSTR_IS_INTERNED(Z_STR_P(zv))) {
     449      928812 :                         Z_TYPE_FLAGS_P(zv) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
     450             :                 }
     451             :         }
     452     1261866 :         ZVAL_COPY_VALUE(CT_CONSTANT_EX(op_array, literal_position), zv);
     453     1261866 :         Z_CACHE_SLOT(op_array->literals[literal_position]) = -1;
     454     1261866 : }
     455             : /* }}} */
     456             : 
     457             : /* Is used while compiling a function, using the context to keep track
     458             :    of an approximate size to avoid to relocate to often.
     459             :    Literals are truncated to actual size in the second compiler pass (pass_two()). */
     460     1261866 : int zend_add_literal(zend_op_array *op_array, zval *zv) /* {{{ */
     461             : {
     462     1261866 :         int i = op_array->last_literal;
     463     1261866 :         op_array->last_literal++;
     464     1261866 :         if (i >= CG(context).literals_size) {
     465      359322 :                 while (i >= CG(context).literals_size) {
     466      119774 :                         CG(context).literals_size += 16; /* FIXME */
     467             :                 }
     468      119774 :                 op_array->literals = (zval*)erealloc(op_array->literals, CG(context).literals_size * sizeof(zval));
     469             :         }
     470     1261866 :         zend_insert_literal(op_array, zv, i);
     471     1261866 :         return i;
     472             : }
     473             : /* }}} */
     474             : 
     475      209205 : static inline int zend_add_literal_string(zend_op_array *op_array, zend_string **str) /* {{{ */
     476             : {
     477             :         int ret;
     478             :         zval zv;
     479      209205 :         ZVAL_STR(&zv, *str);
     480      209205 :         ret = zend_add_literal(op_array, &zv);
     481      209205 :         *str = Z_STR(zv);
     482      209205 :         return ret;
     483             : }
     484             : /* }}} */
     485             : 
     486       54630 : static int zend_add_func_name_literal(zend_op_array *op_array, zend_string *name) /* {{{ */
     487             : {
     488             :         /* Original name */
     489       54630 :         int ret = zend_add_literal_string(op_array, &name);
     490             : 
     491             :         /* Lowercased name */
     492       54630 :         zend_string *lc_name = zend_string_tolower(name);
     493       54630 :         zend_add_literal_string(op_array, &lc_name);
     494             : 
     495       54630 :         return ret;
     496             : }
     497             : /* }}} */
     498             : 
     499         375 : static int zend_add_ns_func_name_literal(zend_op_array *op_array, zend_string *name) /* {{{ */
     500             : {
     501             :         const char *unqualified_name;
     502             :         size_t unqualified_name_len;
     503             : 
     504             :         /* Original name */
     505         375 :         int ret = zend_add_literal_string(op_array, &name);
     506             : 
     507             :         /* Lowercased name */
     508         375 :         zend_string *lc_name = zend_string_tolower(name);
     509         375 :         zend_add_literal_string(op_array, &lc_name);
     510             : 
     511             :         /* Lowercased unqualfied name */
     512         375 :         if (zend_get_unqualified_name(name, &unqualified_name, &unqualified_name_len)) {
     513         750 :                 lc_name = zend_string_alloc(unqualified_name_len, 0);
     514         375 :                 zend_str_tolower_copy(ZSTR_VAL(lc_name), unqualified_name, unqualified_name_len);
     515         375 :                 zend_add_literal_string(op_array, &lc_name);
     516             :         }
     517             : 
     518         375 :         return ret;
     519             : }
     520             : /* }}} */
     521             : 
     522       26665 : static int zend_add_class_name_literal(zend_op_array *op_array, zend_string *name) /* {{{ */
     523             : {
     524             :         /* Original name */
     525       26665 :         int ret = zend_add_literal_string(op_array, &name);
     526             : 
     527             :         /* Lowercased name */
     528       26665 :         zend_string *lc_name = zend_string_tolower(name);
     529       26665 :         zend_add_literal_string(op_array, &lc_name);
     530             : 
     531       26665 :         zend_alloc_cache_slot(ret);
     532             : 
     533       26665 :         return ret;
     534             : }
     535             : /* }}} */
     536             : 
     537        5708 : static int zend_add_const_name_literal(zend_op_array *op_array, zend_string *name, zend_bool unqualified) /* {{{ */
     538             : {
     539             :         zend_string *tmp_name;
     540             : 
     541        5708 :         int ret = zend_add_literal_string(op_array, &name);
     542             : 
     543        5708 :         size_t ns_len = 0, after_ns_len = ZSTR_LEN(name);
     544       11416 :         const char *after_ns = zend_memrchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name));
     545        5708 :         if (after_ns) {
     546          87 :                 after_ns += 1;
     547          87 :                 ns_len = after_ns - ZSTR_VAL(name) - 1;
     548          87 :                 after_ns_len = ZSTR_LEN(name) - ns_len - 1;
     549             : 
     550             :                 /* lowercased namespace name & original constant name */
     551         174 :                 tmp_name = zend_string_init(ZSTR_VAL(name), ZSTR_LEN(name), 0);
     552          87 :                 zend_str_tolower(ZSTR_VAL(tmp_name), ns_len);
     553          87 :                 zend_add_literal_string(op_array, &tmp_name);
     554             : 
     555             :                 /* lowercased namespace name & lowercased constant name */
     556          87 :                 tmp_name = zend_string_tolower(name);
     557          87 :                 zend_add_literal_string(op_array, &tmp_name);
     558             : 
     559          87 :                 if (!unqualified) {
     560          60 :                         return ret;
     561             :                 }
     562             :         } else {
     563        5621 :                 after_ns = ZSTR_VAL(name);
     564             :         }
     565             : 
     566             :         /* original unqualified constant name */
     567        5648 :         tmp_name = zend_string_init(after_ns, after_ns_len, 0);
     568        5648 :         zend_add_literal_string(op_array, &tmp_name);
     569             : 
     570             :         /* lowercased unqualified constant name */
     571        5648 :         tmp_name = zend_string_alloc(after_ns_len, 0);
     572        5648 :         zend_str_tolower_copy(ZSTR_VAL(tmp_name), after_ns, after_ns_len);
     573        5648 :         zend_add_literal_string(op_array, &tmp_name);
     574             : 
     575        5648 :         return ret;
     576             : }
     577             : /* }}} */
     578             : 
     579             : #define LITERAL_STR(op, str) do { \
     580             :                 zval _c; \
     581             :                 ZVAL_STR(&_c, str); \
     582             :                 op.constant = zend_add_literal(CG(active_op_array), &_c); \
     583             :         } while (0)
     584             : 
     585         277 : void zend_stop_lexing(void)
     586             : {
     587         277 :         if (LANG_SCNG(on_event)) {
     588           0 :                 LANG_SCNG(on_event)(ON_STOP, END, 0, LANG_SCNG(on_event_context));
     589             :         }
     590             : 
     591         277 :         LANG_SCNG(yy_cursor) = LANG_SCNG(yy_limit);
     592         277 : }
     593             : 
     594       45951 : static uint32_t zend_start_live_range(zend_op_array *op_array, uint32_t start) /* {{{ */
     595             : {
     596             :         zend_live_range *range;
     597             : 
     598       45951 :         op_array->last_live_range++;
     599       45951 :         op_array->live_range = erealloc(op_array->live_range, sizeof(zend_live_range) * op_array->last_live_range);
     600       45951 :         range = op_array->live_range + op_array->last_live_range - 1;
     601       45951 :         range->start = start;
     602       45951 :         return op_array->last_live_range - 1;
     603             : }
     604             : /* }}} */
     605             : 
     606       14814 : static uint32_t zend_start_live_range_ex(zend_op_array *op_array, uint32_t start) /* {{{ */
     607             : {
     608       24908 :         if (op_array->last_live_range == 0 ||
     609       10094 :             op_array->live_range[op_array->last_live_range - 1].start <= start) {
     610       13901 :                 return zend_start_live_range(op_array, start);
     611             :         } else {
     612             :                 /* Live ranges have to be sorted by "start" field */
     613         913 :                 uint32_t n = op_array->last_live_range;
     614             : 
     615             :                 /* move early ranges to make a room */
     616         913 :                 op_array->last_live_range = n + 1;
     617         913 :                 op_array->live_range = erealloc(op_array->live_range, sizeof(zend_live_range) * op_array->last_live_range);
     618             :                 do {
     619        2324 :                         op_array->live_range[n] = op_array->live_range[n-1];
     620        2324 :                         n--;
     621        2324 :                 } while (n != 0 && op_array->live_range[n-1].start > start);
     622             : 
     623             :             /* initialize new range */
     624         913 :                 op_array->live_range[n].start = start;
     625             : 
     626             :                 /* update referens to live-ranges from stack */
     627         913 :                 if (!zend_stack_is_empty(&CG(loop_var_stack))) {
     628          70 :                         zend_loop_var *loop_var = zend_stack_top(&CG(loop_var_stack));
     629          70 :                         zend_loop_var *base = zend_stack_base(&CG(loop_var_stack));
     630          70 :                         int check_opcodes = 0;
     631             : 
     632          71 :                         for (; loop_var >= base; loop_var--) {
     633          70 :                                 if (loop_var->opcode == ZEND_RETURN) {
     634             :                                         /* Stack separator */
     635          63 :                                         break;
     636          14 :                                 } else if (loop_var->opcode == ZEND_FREE ||
     637           7 :                                    loop_var->opcode == ZEND_FE_FREE) {
     638           6 :                                         if (loop_var->u.live_range_offset >= n) {
     639           0 :                                                 loop_var->u.live_range_offset++;
     640           0 :                                                 check_opcodes = 1;
     641             :                                         } else {
     642           6 :                                                 break;
     643             :                                         }
     644             :                                 }
     645             :                         }
     646             : 
     647             :                         /* update previously generated FREE/FE_FREE opcodes */
     648          70 :                         if (check_opcodes) {
     649           0 :                                 zend_op *opline = op_array->opcodes + op_array->live_range[n+1].start;
     650           0 :                                 zend_op *end = op_array->opcodes + op_array->last;
     651             : 
     652           0 :                                 while (opline < end) {
     653           0 :                                         if ((opline->opcode == ZEND_FREE ||
     654           0 :                                              opline->opcode == ZEND_FE_FREE) &&
     655           0 :                                             (opline->extended_value & ZEND_FREE_ON_RETURN) &&
     656           0 :                                             opline->op2.num >= n) {
     657           0 :                                                 opline->op2.num++;
     658             :                                         }
     659           0 :                                         opline++;
     660             :                                 }
     661             :                         }
     662             :                 }
     663         913 :                 return n;
     664             :         }
     665             : }
     666             : /* }}} */
     667             : 
     668       46859 : static void zend_end_live_range(zend_op_array *op_array, uint32_t offset, uint32_t end, uint32_t kind, uint32_t var) /* {{{ */
     669             : {
     670       46859 :         zend_live_range *range = op_array->live_range + offset;
     671             : 
     672       46859 :         if (range->start == end && offset == (uint32_t)op_array->last_live_range - 1) {
     673           0 :                 op_array->last_live_range--;
     674             :         } else {
     675       46859 :                 range->end = end;
     676       46859 :                 range->var = (var * sizeof(zval)) | kind;
     677             :         }
     678       46859 : }
     679             : /* }}} */
     680             : 
     681       17128 : static inline void zend_begin_loop(zend_uchar free_opcode, const znode *loop_var) /* {{{ */
     682             : {
     683             :         zend_brk_cont_element *brk_cont_element;
     684       17128 :         int parent = CG(context).current_brk_cont;
     685       17128 :         zend_loop_var info = {0};
     686             : 
     687       17128 :         CG(context).current_brk_cont = CG(context).last_brk_cont;
     688       17128 :         brk_cont_element = get_next_brk_cont_element();
     689       17128 :         brk_cont_element->parent = parent;
     690             : 
     691       29232 :         if (loop_var && (loop_var->op_type & (IS_VAR|IS_TMP_VAR))) {
     692       12104 :                 uint32_t start = get_next_op_number(CG(active_op_array));
     693             : 
     694       12104 :                 info.opcode = free_opcode;
     695       12104 :                 info.var_type = loop_var->op_type;
     696       12104 :                 info.var_num = loop_var->u.op.var;
     697       12104 :                 info.u.live_range_offset = zend_start_live_range(CG(active_op_array), start);
     698       12104 :                 brk_cont_element->start = start;
     699             :         } else {
     700        5024 :                 info.opcode = ZEND_NOP;
     701             :                 /* The start field is used to free temporary variables in case of exceptions.
     702             :                  * We won't try to free something of we don't have loop variable.  */
     703        5024 :                 brk_cont_element->start = -1;
     704             :         }
     705             : 
     706       17128 :         zend_stack_push(&CG(loop_var_stack), &info);
     707       17128 : }
     708             : /* }}} */
     709             : 
     710       17121 : static inline void zend_end_loop(int cont_addr, const znode *var_node) /* {{{ */
     711             : {
     712       17121 :         uint32_t end = get_next_op_number(CG(active_op_array));
     713             :         zend_brk_cont_element *brk_cont_element
     714       17121 :                 = &CG(context).brk_cont_array[CG(context).current_brk_cont];
     715       17121 :         brk_cont_element->cont = cont_addr;
     716       17121 :         brk_cont_element->brk = end;
     717       17121 :         CG(context).current_brk_cont = brk_cont_element->parent;
     718             : 
     719       17121 :         if (brk_cont_element->start != -1) {
     720       12099 :                 zend_loop_var *loop_var = zend_stack_top(&CG(loop_var_stack));
     721       12099 :                 zend_end_live_range(CG(active_op_array), loop_var->u.live_range_offset, end,
     722             :                         loop_var->opcode == ZEND_FE_FREE ? ZEND_LIVE_LOOP : ZEND_LIVE_TMPVAR,
     723             :                         var_node->u.op.var);
     724             :         }
     725             : 
     726       17121 :         zend_stack_del_top(&CG(loop_var_stack));
     727       17121 : }
     728             : /* }}} */
     729             : 
     730      329249 : void zend_do_free(znode *op1) /* {{{ */
     731             : {
     732      329249 :         if (op1->op_type == IS_TMP_VAR) {
     733        7032 :                 zend_op *opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
     734             : 
     735       14066 :                 while (opline->opcode == ZEND_END_SILENCE) {
     736           2 :                         opline--;
     737             :                 }
     738             : 
     739        7032 :                 if (opline->result_type == IS_TMP_VAR && opline->result.var == op1->u.op.var) {
     740        6997 :                         if (opline->opcode == ZEND_BOOL || opline->opcode == ZEND_BOOL_NOT) {
     741         914 :                                 return;
     742             :                         }
     743             :                 }
     744             : 
     745        6118 :                 zend_emit_op(NULL, ZEND_FREE, op1, NULL);
     746      322217 :         } else if (op1->op_type == IS_VAR) {
     747      295269 :                 zend_op *opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
     748     1217286 :                 while (opline->opcode == ZEND_END_SILENCE ||
     749      306785 :                                 opline->opcode == ZEND_EXT_FCALL_END ||
     750      306785 :                                 opline->opcode == ZEND_OP_DATA) {
     751       13178 :                         opline--;
     752             :                 }
     753      885117 :                 if (opline->result_type == IS_VAR
     754      590193 :                         && opline->result.var == op1->u.op.var) {
     755     1179678 :                         if (opline->opcode == ZEND_FETCH_R ||
     756      294922 :                             opline->opcode == ZEND_FETCH_DIM_R ||
     757      294903 :                             opline->opcode == ZEND_FETCH_OBJ_R ||
     758      294884 :                             opline->opcode == ZEND_FETCH_STATIC_PROP_R) {
     759             :                                 /* It's very rare and useless case. It's better to use
     760             :                                    additional FREE opcode and simplify the FETCH handlers
     761             :                                    their selves */
     762          45 :                                 zend_emit_op(NULL, ZEND_FREE, op1, NULL);
     763      294879 :                         } else if (opline->opcode == ZEND_FETCH_THIS) {
     764           1 :                                 opline->opcode = ZEND_NOP;
     765           1 :                                 opline->result_type = IS_UNUSED;
     766             :                         } else {
     767      294878 :                                 opline->result_type = IS_UNUSED;
     768             :                         }
     769             :                 } else {
     770        1353 :                         while (opline >= CG(active_op_array)->opcodes) {
     771        1272 :                                 if (opline->opcode == ZEND_FETCH_LIST &&
     772         132 :                                     opline->op1_type == IS_VAR &&
     773         132 :                                     opline->op1.var == op1->u.op.var) {
     774         119 :                                         zend_emit_op(NULL, ZEND_FREE, op1, NULL);
     775         119 :                                         return;
     776             :                                 }
     777        1170 :                                 if (opline->result_type == IS_VAR
     778        1170 :                                         && opline->result.var == op1->u.op.var) {
     779         226 :                                         if (opline->opcode == ZEND_NEW) {
     780         226 :                                                 zend_emit_op(NULL, ZEND_FREE, op1, NULL);
     781             :                                         }
     782         226 :                                         break;
     783             :                                 }
     784         663 :                                 opline--;
     785             :                         }
     786             :                 }
     787       26948 :         } else if (op1->op_type == IS_CONST) {
     788             :                 /* Destroy value without using GC: When opcache moves arrays into SHM it will
     789             :                  * free the zend_array structure, so references to it from outside the op array
     790             :                  * become invalid. GC would cause such a reference in the root buffer. */
     791       26641 :                 zval_ptr_dtor_nogc(&op1->u.constant);
     792             :         }
     793             : }
     794             : /* }}} */
     795             : 
     796           2 : uint32_t zend_add_class_modifier(uint32_t flags, uint32_t new_flag) /* {{{ */
     797             : {
     798           2 :         uint32_t new_flags = flags | new_flag;
     799           2 :         if ((flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS) && (new_flag & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
     800           0 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple abstract modifiers are not allowed");
     801             :         }
     802           2 :         if ((flags & ZEND_ACC_FINAL) && (new_flag & ZEND_ACC_FINAL)) {
     803           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple final modifiers are not allowed");
     804             :         }
     805           1 :         if ((new_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS) && (new_flags & ZEND_ACC_FINAL)) {
     806           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use the final modifier on an abstract class");
     807             :         }
     808           0 :         return new_flags;
     809             : }
     810             : /* }}} */
     811             : 
     812         824 : uint32_t zend_add_member_modifier(uint32_t flags, uint32_t new_flag) /* {{{ */
     813             : {
     814         824 :         uint32_t new_flags = flags | new_flag;
     815         824 :         if ((flags & ZEND_ACC_PPP_MASK) && (new_flag & ZEND_ACC_PPP_MASK)) {
     816           4 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple access type modifiers are not allowed");
     817             :         }
     818         820 :         if ((flags & ZEND_ACC_ABSTRACT) && (new_flag & ZEND_ACC_ABSTRACT)) {
     819           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple abstract modifiers are not allowed");
     820             :         }
     821         819 :         if ((flags & ZEND_ACC_STATIC) && (new_flag & ZEND_ACC_STATIC)) {
     822           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple static modifiers are not allowed");
     823             :         }
     824         818 :         if ((flags & ZEND_ACC_FINAL) && (new_flag & ZEND_ACC_FINAL)) {
     825           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple final modifiers are not allowed");
     826             :         }
     827         817 :         if ((new_flags & ZEND_ACC_ABSTRACT) && (new_flags & ZEND_ACC_FINAL)) {
     828           4 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use the final modifier on an abstract class member");
     829             :         }
     830         813 :         return new_flags;
     831             : }
     832             : /* }}} */
     833             : 
     834        2392 : zend_string *zend_concat3(char *str1, size_t str1_len, char *str2, size_t str2_len, char *str3, size_t str3_len) /* {{{ */
     835             : {
     836        2392 :         size_t len = str1_len + str2_len + str3_len;
     837        2392 :         zend_string *res = zend_string_alloc(len, 0);
     838             : 
     839        2392 :         memcpy(ZSTR_VAL(res), str1, str1_len);
     840        2392 :         memcpy(ZSTR_VAL(res) + str1_len, str2, str2_len);
     841        2392 :         memcpy(ZSTR_VAL(res) + str1_len + str2_len, str3, str3_len);
     842        2392 :         ZSTR_VAL(res)[len] = '\0';
     843             : 
     844        2392 :         return res;
     845             : }
     846             : 
     847        1131 : zend_string *zend_concat_names(char *name1, size_t name1_len, char *name2, size_t name2_len) {
     848        1131 :         return zend_concat3(name1, name1_len, "\\", 1, name2, name2_len);
     849             : }
     850             : 
     851      445884 : zend_string *zend_prefix_with_ns(zend_string *name) {
     852      445884 :         if (FC(current_namespace)) {
     853        1061 :                 zend_string *ns = FC(current_namespace);
     854        1061 :                 return zend_concat_names(ZSTR_VAL(ns), ZSTR_LEN(ns), ZSTR_VAL(name), ZSTR_LEN(name));
     855             :         } else {
     856      444823 :                 return zend_string_copy(name);
     857             :         }
     858             : }
     859             : 
     860       41706 : void *zend_hash_find_ptr_lc(HashTable *ht, const char *str, size_t len) {
     861             :         void *result;
     862             :         zend_string *lcname;
     863             :         ALLOCA_FLAG(use_heap);
     864             : 
     865       83412 :         ZSTR_ALLOCA_ALLOC(lcname, len, use_heap);
     866       41706 :         zend_str_tolower_copy(ZSTR_VAL(lcname), str, len);
     867       41706 :         result = zend_hash_find_ptr(ht, lcname);
     868       41706 :         ZSTR_ALLOCA_FREE(lcname, use_heap);
     869             : 
     870       41706 :         return result;
     871             : }
     872             : 
     873      379223 : zend_string *zend_resolve_non_class_name(
     874             :         zend_string *name, uint32_t type, zend_bool *is_fully_qualified,
     875             :         zend_bool case_sensitive, HashTable *current_import_sub
     876             : ) {
     877             :         char *compound;
     878      379223 :         *is_fully_qualified = 0;
     879             : 
     880      379223 :         if (ZSTR_VAL(name)[0] == '\\') {
     881             :                 /* Remove \ prefix (only relevant if this is a string rather than a label) */
     882           2 :                 *is_fully_qualified = 1;
     883           4 :                 return zend_string_init(ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 1, 0);
     884             :         }
     885             : 
     886      379221 :         if (type == ZEND_NAME_FQ) {
     887         188 :                 *is_fully_qualified = 1;
     888         188 :                 return zend_string_copy(name);
     889             :         }
     890             : 
     891      379033 :         if (type == ZEND_NAME_RELATIVE) {
     892          46 :                 *is_fully_qualified = 1;
     893          46 :                 return zend_prefix_with_ns(name);
     894             :         }
     895             : 
     896      378987 :         if (current_import_sub) {
     897             :                 /* If an unqualified name is a function/const alias, replace it. */
     898             :                 zend_string *import_name;
     899          78 :                 if (case_sensitive) {
     900          22 :                         import_name = zend_hash_find_ptr(current_import_sub, name);
     901             :                 } else {
     902          56 :                         import_name = zend_hash_find_ptr_lc(current_import_sub, ZSTR_VAL(name), ZSTR_LEN(name));
     903             :                 }
     904             : 
     905          78 :                 if (import_name) {
     906          40 :                         *is_fully_qualified = 1;
     907          40 :                         return zend_string_copy(import_name);
     908             :                 }
     909             :         }
     910             : 
     911      378947 :         compound = memchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name));
     912      378947 :         if (compound) {
     913          71 :                 *is_fully_qualified = 1;
     914             :         }
     915             : 
     916      378947 :         if (compound && FC(imports)) {
     917             :                 /* If the first part of a qualified name is an alias, substitute it. */
     918          42 :                 size_t len = compound - ZSTR_VAL(name);
     919          42 :                 zend_string *import_name = zend_hash_find_ptr_lc(FC(imports), ZSTR_VAL(name), len);
     920             : 
     921          42 :                 if (import_name) {
     922          13 :                         return zend_concat_names(
     923          13 :                                 ZSTR_VAL(import_name), ZSTR_LEN(import_name), ZSTR_VAL(name) + len + 1, ZSTR_LEN(name) - len - 1);
     924             :                 }
     925             :         }
     926             : 
     927      378934 :         return zend_prefix_with_ns(name);
     928             : }
     929             : /* }}} */
     930             : 
     931      287360 : zend_string *zend_resolve_function_name(zend_string *name, uint32_t type, zend_bool *is_fully_qualified) /* {{{ */
     932             : {
     933      287360 :         return zend_resolve_non_class_name(
     934             :                 name, type, is_fully_qualified, 0, FC(imports_function));
     935             : }
     936             : /* }}} */
     937             : 
     938       91863 : zend_string *zend_resolve_const_name(zend_string *name, uint32_t type, zend_bool *is_fully_qualified) /* {{{ */ {
     939       91863 :         return zend_resolve_non_class_name(
     940             :                 name, type, is_fully_qualified, 1, FC(imports_const));
     941             : }
     942             : /* }}} */
     943             : 
     944       38196 : zend_string *zend_resolve_class_name(zend_string *name, uint32_t type) /* {{{ */
     945             : {
     946             :         char *compound;
     947             : 
     948       38196 :         if (type == ZEND_NAME_RELATIVE) {
     949          26 :                 return zend_prefix_with_ns(name);
     950             :         }
     951             : 
     952       38170 :         if (type == ZEND_NAME_FQ || ZSTR_VAL(name)[0] == '\\') {
     953             :                 /* Remove \ prefix (only relevant if this is a string rather than a label) */
     954         316 :                 if (ZSTR_VAL(name)[0] == '\\') {
     955           2 :                         name = zend_string_init(ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 1, 0);
     956             :                 } else {
     957             :                         zend_string_addref(name);
     958             :                 }
     959             :                 /* Ensure that \self, \parent and \static are not used */
     960         316 :                 if (ZEND_FETCH_CLASS_DEFAULT != zend_get_class_fetch_type(name)) {
     961           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "'\\%s' is an invalid class name", ZSTR_VAL(name));
     962             :                 }
     963         315 :                 return name;
     964             :         }
     965             : 
     966       37854 :         if (FC(imports)) {
     967         190 :                 compound = memchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name));
     968         190 :                 if (compound) {
     969             :                         /* If the first part of a qualified name is an alias, substitute it. */
     970          26 :                         size_t len = compound - ZSTR_VAL(name);
     971             :                         zend_string *import_name =
     972          26 :                                 zend_hash_find_ptr_lc(FC(imports), ZSTR_VAL(name), len);
     973             : 
     974          26 :                         if (import_name) {
     975          16 :                                 return zend_concat_names(
     976          16 :                                         ZSTR_VAL(import_name), ZSTR_LEN(import_name), ZSTR_VAL(name) + len + 1, ZSTR_LEN(name) - len - 1);
     977             :                         }
     978             :                 } else {
     979             :                         /* If an unqualified name is an alias, replace it. */
     980             :                         zend_string *import_name
     981         164 :                                 = zend_hash_find_ptr_lc(FC(imports), ZSTR_VAL(name), ZSTR_LEN(name));
     982             : 
     983         164 :                         if (import_name) {
     984          72 :                                 return zend_string_copy(import_name);
     985             :                         }
     986             :                 }
     987             :         }
     988             : 
     989             :         /* If not fully qualified and not an alias, prepend the current namespace */
     990       37766 :         return zend_prefix_with_ns(name);
     991             : }
     992             : /* }}} */
     993             : 
     994       35692 : zend_string *zend_resolve_class_name_ast(zend_ast *ast) /* {{{ */
     995             : {
     996       35692 :         zval *class_name = zend_ast_get_zval(ast);
     997       35692 :         if (Z_TYPE_P(class_name) != IS_STRING) {
     998           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Illegal class name");
     999             :         }
    1000       35691 :         return zend_resolve_class_name(Z_STR_P(class_name), ast->attr);
    1001             : }
    1002             : /* }}} */
    1003             : 
    1004          37 : static void label_ptr_dtor(zval *zv) /* {{{ */
    1005             : {
    1006          37 :         efree_size(Z_PTR_P(zv), sizeof(zend_label));
    1007          37 : }
    1008             : /* }}} */
    1009             : 
    1010         119 : static void str_dtor(zval *zv)  /* {{{ */ {
    1011         119 :         zend_string_release(Z_STR_P(zv));
    1012         119 : }
    1013             : /* }}} */
    1014             : 
    1015             : static zend_bool zend_is_call(zend_ast *ast);
    1016             : 
    1017        2937 : static uint32_t zend_add_try_element(uint32_t try_op) /* {{{ */
    1018             : {
    1019        2937 :         zend_op_array *op_array = CG(active_op_array);
    1020        2937 :         uint32_t try_catch_offset = op_array->last_try_catch++;
    1021             :         zend_try_catch_element *elem;
    1022             : 
    1023        2937 :         op_array->try_catch_array = safe_erealloc(
    1024             :                 op_array->try_catch_array, sizeof(zend_try_catch_element), op_array->last_try_catch, 0);
    1025             : 
    1026        2937 :         elem = &op_array->try_catch_array[try_catch_offset];
    1027        2937 :         elem->try_op = try_op;
    1028        2937 :         elem->catch_op = 0;
    1029        2937 :         elem->finally_op = 0;
    1030        2937 :         elem->finally_end = 0;
    1031             : 
    1032        2937 :         return try_catch_offset;
    1033             : }
    1034             : /* }}} */
    1035             : 
    1036         553 : ZEND_API void function_add_ref(zend_function *function) /* {{{ */
    1037             : {
    1038         553 :         if (function->type == ZEND_USER_FUNCTION) {
    1039         247 :                 zend_op_array *op_array = &function->op_array;
    1040             : 
    1041         247 :                 if (op_array->refcount) {
    1042         247 :                         (*op_array->refcount)++;
    1043             :                 }
    1044         247 :                 if (op_array->static_variables) {
    1045           4 :                         if (!(GC_FLAGS(op_array->static_variables) & IS_ARRAY_IMMUTABLE)) {
    1046           4 :                                 GC_REFCOUNT(op_array->static_variables)++;
    1047             :                         }
    1048             :                 }
    1049         247 :                 op_array->run_time_cache = NULL;
    1050         306 :         } else if (function->type == ZEND_INTERNAL_FUNCTION) {
    1051         306 :                 if (function->common.function_name) {
    1052         306 :                         zend_string_addref(function->common.function_name);
    1053             :                 }
    1054             :         }
    1055         553 : }
    1056             : /* }}} */
    1057             : 
    1058       19001 : ZEND_API int do_bind_function(const zend_op_array *op_array, const zend_op *opline, HashTable *function_table, zend_bool compile_time) /* {{{ */
    1059             : {
    1060             :         zend_function *function, *new_function;
    1061             :         zval *lcname, *rtd_key;
    1062             : 
    1063       19001 :         if (compile_time) {
    1064       15558 :                 lcname = CT_CONSTANT_EX(op_array, opline->op1.constant);
    1065       15558 :                 rtd_key = lcname + 1;
    1066             :         } else {
    1067        3443 :                 lcname = RT_CONSTANT(op_array, opline->op1);
    1068        3443 :                 rtd_key = lcname + 1;
    1069             :         }
    1070             : 
    1071       38002 :         function = zend_hash_find_ptr(function_table, Z_STR_P(rtd_key));
    1072       19001 :         new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
    1073       19001 :         memcpy(new_function, function, sizeof(zend_op_array));
    1074       38002 :         if (zend_hash_add_ptr(function_table, Z_STR_P(lcname), new_function) == NULL) {
    1075           1 :                 int error_level = compile_time ? E_COMPILE_ERROR : E_ERROR;
    1076             :                 zend_function *old_function;
    1077             : 
    1078           4 :                 if ((old_function = zend_hash_find_ptr(function_table, Z_STR_P(lcname))) != NULL
    1079             :                         && old_function->type == ZEND_USER_FUNCTION
    1080           2 :                         && old_function->op_array.last > 0) {
    1081           3 :                         zend_error_noreturn(error_level, "Cannot redeclare %s() (previously declared in %s:%d)",
    1082           1 :                                                 ZSTR_VAL(function->common.function_name),
    1083           1 :                                                 ZSTR_VAL(old_function->op_array.filename),
    1084           1 :                                                 old_function->op_array.opcodes[0].lineno);
    1085             :                 } else {
    1086           0 :                         zend_error_noreturn(error_level, "Cannot redeclare %s()", ZSTR_VAL(function->common.function_name));
    1087             :                 }
    1088             :                 return FAILURE;
    1089             :         } else {
    1090       19000 :                 if (function->op_array.refcount) {
    1091       19000 :                         (*function->op_array.refcount)++;
    1092             :                 }
    1093       19000 :                 function->op_array.static_variables = NULL; /* NULL out the unbound function */
    1094       19000 :                 return SUCCESS;
    1095             :         }
    1096             : }
    1097             : /* }}} */
    1098             : 
    1099        5510 : ZEND_API zend_class_entry *do_bind_class(const zend_op_array* op_array, const zend_op *opline, HashTable *class_table, zend_bool compile_time) /* {{{ */
    1100             : {
    1101             :         zend_class_entry *ce;
    1102             :         zval *lcname, *rtd_key;
    1103             : 
    1104        5510 :         if (compile_time) {
    1105        5032 :                 lcname = CT_CONSTANT_EX(op_array, opline->op1.constant);
    1106        5032 :                 rtd_key = lcname + 1;
    1107             :         } else {
    1108         478 :                 lcname = RT_CONSTANT(op_array, opline->op1);
    1109         478 :                 rtd_key = lcname + 1;
    1110             :         }
    1111       11020 :         if ((ce = zend_hash_find_ptr(class_table, Z_STR_P(rtd_key))) == NULL) {
    1112           0 :                 zend_error_noreturn(E_COMPILE_ERROR, "Internal Zend error - Missing class information for %s", Z_STRVAL_P(rtd_key));
    1113             :                 return NULL;
    1114             :         }
    1115        5510 :         ce->refcount++;
    1116       11020 :         if (zend_hash_add_ptr(class_table, Z_STR_P(lcname), ce) == NULL) {
    1117          16 :                 ce->refcount--;
    1118          16 :                 if (!compile_time) {
    1119             :                         /* If we're in compile time, in practice, it's quite possible
    1120             :                          * that we'll never reach this class declaration at runtime,
    1121             :                          * so we shut up about it.  This allows the if (!defined('FOO')) { return; }
    1122             :                          * approach to work.
    1123             :                          */
    1124           8 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), ZSTR_VAL(ce->name));
    1125             :                 }
    1126           8 :                 return NULL;
    1127             :         } else {
    1128        5494 :                 if (!(ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_IMPLEMENT_INTERFACES|ZEND_ACC_IMPLEMENT_TRAITS))) {
    1129        4866 :                         zend_verify_abstract_class(ce);
    1130             :                 }
    1131        5491 :                 return ce;
    1132             :         }
    1133             : }
    1134             : /* }}} */
    1135             : 
    1136        2497 : ZEND_API zend_class_entry *do_bind_inherited_class(const zend_op_array *op_array, const zend_op *opline, HashTable *class_table, zend_class_entry *parent_ce, zend_bool compile_time) /* {{{ */
    1137             : {
    1138             :         zend_class_entry *ce;
    1139             :         zval *lcname, *rtd_key;
    1140             : 
    1141        2497 :         if (compile_time) {
    1142        1181 :                 lcname = CT_CONSTANT_EX(op_array, opline->op1.constant);
    1143        1181 :                 rtd_key = lcname + 1;
    1144             :         } else {
    1145        1316 :                 lcname = RT_CONSTANT(op_array, opline->op1);
    1146        1316 :                 rtd_key = lcname + 1;
    1147             :         }
    1148             : 
    1149        4994 :         ce = zend_hash_find_ptr(class_table, Z_STR_P(rtd_key));
    1150             : 
    1151        2497 :         if (!ce) {
    1152           0 :                 if (!compile_time) {
    1153             :                         /* If we're in compile time, in practice, it's quite possible
    1154             :                          * that we'll never reach this class declaration at runtime,
    1155             :                          * so we shut up about it.  This allows the if (!defined('FOO')) { return; }
    1156             :                          * approach to work.
    1157             :                          */
    1158           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare  %s, because the name is already in use", zend_get_object_type(Z_OBJCE_P(lcname)));
    1159             :                 }
    1160           0 :                 return NULL;
    1161             :         }
    1162             : 
    1163        2497 :         if (zend_hash_exists(class_table, Z_STR_P(lcname))) {
    1164           0 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), ZSTR_VAL(ce->name));
    1165             :         }
    1166             : 
    1167        2497 :         zend_do_inheritance(ce, parent_ce);
    1168             : 
    1169        2441 :         ce->refcount++;
    1170             : 
    1171             :         /* Register the derived class */
    1172        4882 :         if (zend_hash_add_ptr(class_table, Z_STR_P(lcname), ce) == NULL) {
    1173           0 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), ZSTR_VAL(ce->name));
    1174             :         }
    1175        2441 :         return ce;
    1176             : }
    1177             : /* }}} */
    1178             : 
    1179       22623 : void zend_do_early_binding(void) /* {{{ */
    1180             : {
    1181       22623 :         zend_op *opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
    1182             :         HashTable *table;
    1183             : 
    1184       45246 :         while (opline->opcode == ZEND_TICKS && opline > CG(active_op_array)->opcodes) {
    1185           0 :                 opline--;
    1186             :         }
    1187             : 
    1188       22623 :         switch (opline->opcode) {
    1189             :                 case ZEND_DECLARE_FUNCTION:
    1190       15558 :                         if (do_bind_function(CG(active_op_array), opline, CG(function_table), 1) == FAILURE) {
    1191           0 :                                 return;
    1192             :                         }
    1193       15557 :                         table = CG(function_table);
    1194       15557 :                         break;
    1195             :                 case ZEND_DECLARE_CLASS:
    1196        5032 :                         if (do_bind_class(CG(active_op_array), opline, CG(class_table), 1) == NULL) {
    1197           8 :                                 return;
    1198             :                         }
    1199        5021 :                         table = CG(class_table);
    1200        5021 :                         break;
    1201             :                 case ZEND_DECLARE_INHERITED_CLASS:
    1202             :                         {
    1203        1483 :                                 zend_op *fetch_class_opline = opline-1;
    1204             :                                 zval *parent_name;
    1205             :                                 zend_class_entry *ce;
    1206             : 
    1207        1483 :                                 parent_name = CT_CONSTANT(fetch_class_opline->op2);
    1208        2669 :                                 if (((ce = zend_lookup_class_ex(Z_STR_P(parent_name), parent_name + 1, 0)) == NULL) ||
    1209        1181 :                                     ((CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_CLASSES) &&
    1210           5 :                                      (ce->type == ZEND_INTERNAL_CLASS))) {
    1211         302 :                                         if (CG(compiler_options) & ZEND_COMPILE_DELAYED_BINDING) {
    1212           0 :                                                 uint32_t *opline_num = &CG(active_op_array)->early_binding;
    1213             : 
    1214           0 :                                                 while (*opline_num != (uint32_t)-1) {
    1215           0 :                                                         opline_num = &CG(active_op_array)->opcodes[*opline_num].result.opline_num;
    1216             :                                                 }
    1217           0 :                                                 *opline_num = opline - CG(active_op_array)->opcodes;
    1218           0 :                                                 opline->opcode = ZEND_DECLARE_INHERITED_CLASS_DELAYED;
    1219           0 :                                                 opline->result_type = IS_UNUSED;
    1220           0 :                                                 opline->result.opline_num = -1;
    1221             :                                         }
    1222         302 :                                         return;
    1223             :                                 }
    1224        1181 :                                 if (do_bind_inherited_class(CG(active_op_array), opline, CG(class_table), ce, 1) == NULL) {
    1225           0 :                                         return;
    1226             :                                 }
    1227             :                                 /* clear unnecessary ZEND_FETCH_CLASS opcode */
    1228        1129 :                                 zend_del_literal(CG(active_op_array), fetch_class_opline->op2.constant);
    1229        1129 :                                 MAKE_NOP(fetch_class_opline);
    1230             : 
    1231        1129 :                                 table = CG(class_table);
    1232        1129 :                                 break;
    1233             :                         }
    1234             :                 case ZEND_VERIFY_ABSTRACT_CLASS:
    1235             :                 case ZEND_ADD_INTERFACE:
    1236             :                 case ZEND_ADD_TRAIT:
    1237             :                 case ZEND_BIND_TRAITS:
    1238             :                         /* We currently don't early-bind classes that implement interfaces */
    1239             :                         /* Classes with traits are handled exactly the same, no early-bind here */
    1240         550 :                         return;
    1241             :                 default:
    1242           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Invalid binding type");
    1243             :                         return;
    1244             :         }
    1245             : 
    1246       21707 :         zend_hash_del(table, Z_STR_P(CT_CONSTANT(opline->op1)+1));
    1247       21707 :         zend_del_literal(CG(active_op_array), opline->op1.constant+1);
    1248       21707 :         zend_del_literal(CG(active_op_array), opline->op1.constant);
    1249       21707 :         MAKE_NOP(opline);
    1250             : }
    1251             : /* }}} */
    1252             : 
    1253         506 : static void zend_mark_function_as_generator() /* {{{ */
    1254             : {
    1255         506 :         if (!CG(active_op_array)->function_name) {
    1256           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    1257             :                         "The \"yield\" expression can only be used inside a function");
    1258             :         }
    1259             : 
    1260         505 :         if (CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
    1261          25 :                 zend_arg_info return_info = CG(active_op_array)->arg_info[-1];
    1262             : 
    1263          25 :                 if (return_info.type_hint != IS_ITERABLE) {
    1264          25 :                         const char *msg = "Generators may only declare a return type of Generator, Iterator, Traversable, or iterable, %s is not permitted";
    1265             :                         
    1266          25 :                         if (!return_info.class_name) {
    1267           0 :                                 zend_error_noreturn(E_COMPILE_ERROR, msg, zend_get_type_by_const(return_info.type_hint));
    1268             :                         }
    1269             : 
    1270         111 :                         if (!zend_string_equals_literal_ci(return_info.class_name, "Traversable")
    1271          37 :                                 && !zend_string_equals_literal_ci(return_info.class_name, "Iterator")
    1272          49 :                                 && !zend_string_equals_literal_ci(return_info.class_name, "Generator")) {
    1273           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, msg, ZSTR_VAL(return_info.class_name));
    1274             :                         }
    1275             :                 }
    1276             :         }
    1277             : 
    1278         504 :         CG(active_op_array)->fn_flags |= ZEND_ACC_GENERATOR;
    1279         504 : }
    1280             : /* }}} */
    1281             : 
    1282           0 : ZEND_API void zend_do_delayed_early_binding(const zend_op_array *op_array) /* {{{ */
    1283             : {
    1284           0 :         if (op_array->early_binding != (uint32_t)-1) {
    1285           0 :                 zend_bool orig_in_compilation = CG(in_compilation);
    1286           0 :                 uint32_t opline_num = op_array->early_binding;
    1287             :                 zend_class_entry *ce;
    1288             : 
    1289           0 :                 CG(in_compilation) = 1;
    1290           0 :                 while (opline_num != (uint32_t)-1) {
    1291           0 :                         zval *parent_name = RT_CONSTANT(op_array, op_array->opcodes[opline_num-1].op2);
    1292           0 :                         if ((ce = zend_lookup_class_ex(Z_STR_P(parent_name), parent_name + 1, 0)) != NULL) {
    1293           0 :                                 do_bind_inherited_class(op_array, &op_array->opcodes[opline_num], EG(class_table), ce, 0);
    1294             :                         }
    1295           0 :                         opline_num = op_array->opcodes[opline_num].result.opline_num;
    1296             :                 }
    1297           0 :                 CG(in_compilation) = orig_in_compilation;
    1298             :         }
    1299           0 : }
    1300             : /* }}} */
    1301             : 
    1302      401126 : ZEND_API zend_string *zend_mangle_property_name(const char *src1, size_t src1_length, const char *src2, size_t src2_length, int internal) /* {{{ */
    1303             : {
    1304      401126 :         size_t prop_name_length = 1 + src1_length + 1 + src2_length;
    1305      401126 :         zend_string *prop_name = zend_string_alloc(prop_name_length, internal);
    1306             : 
    1307      401126 :         ZSTR_VAL(prop_name)[0] = '\0';
    1308      401126 :         memcpy(ZSTR_VAL(prop_name) + 1, src1, src1_length+1);
    1309      401126 :         memcpy(ZSTR_VAL(prop_name) + 1 + src1_length + 1, src2, src2_length+1);
    1310      401126 :         return prop_name;
    1311             : }
    1312             : /* }}} */
    1313             : 
    1314             : static zend_always_inline size_t zend_strnlen(const char* s, size_t maxlen) /* {{{ */
    1315             : {
    1316        4272 :         size_t len = 0;
    1317       27203 :         while (*s++ && maxlen--) len++;
    1318        4272 :         return len;
    1319             : }
    1320             : /* }}} */
    1321             : 
    1322        9515 : ZEND_API int zend_unmangle_property_name_ex(const zend_string *name, const char **class_name, const char **prop_name, size_t *prop_len) /* {{{ */
    1323             : {
    1324             :         size_t class_name_len;
    1325             :         size_t anonclass_src_len;
    1326             : 
    1327        9515 :         *class_name = NULL;
    1328             : 
    1329        9515 :         if (!ZSTR_LEN(name) || ZSTR_VAL(name)[0] != '\0') {
    1330        7379 :                 *prop_name = ZSTR_VAL(name);
    1331        7379 :                 if (prop_len) {
    1332        1005 :                         *prop_len = ZSTR_LEN(name);
    1333             :                 }
    1334        7379 :                 return SUCCESS;
    1335             :         }
    1336        2136 :         if (ZSTR_LEN(name) < 3 || ZSTR_VAL(name)[1] == '\0') {
    1337           0 :                 zend_error(E_NOTICE, "Illegal member variable name");
    1338           0 :                 *prop_name = ZSTR_VAL(name);
    1339           0 :                 if (prop_len) {
    1340           0 :                         *prop_len = ZSTR_LEN(name);
    1341             :                 }
    1342           0 :                 return FAILURE;
    1343             :         }
    1344             : 
    1345        4272 :         class_name_len = zend_strnlen(ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 2);
    1346        2136 :         if (class_name_len >= ZSTR_LEN(name) - 2 || ZSTR_VAL(name)[class_name_len + 1] != '\0') {
    1347           0 :                 zend_error(E_NOTICE, "Corrupt member variable name");
    1348           0 :                 *prop_name = ZSTR_VAL(name);
    1349           0 :                 if (prop_len) {
    1350           0 :                         *prop_len = ZSTR_LEN(name);
    1351             :                 }
    1352           0 :                 return FAILURE;
    1353             :         }
    1354             : 
    1355        2136 :         *class_name = ZSTR_VAL(name) + 1;
    1356        4272 :         anonclass_src_len = zend_strnlen(*class_name + class_name_len + 1, ZSTR_LEN(name) - class_name_len - 2);
    1357        2136 :         if (class_name_len + anonclass_src_len + 2 != ZSTR_LEN(name)) {
    1358           1 :                 class_name_len += anonclass_src_len + 1;
    1359             :         }
    1360        2136 :         *prop_name = ZSTR_VAL(name) + class_name_len + 2;
    1361        2136 :         if (prop_len) {
    1362         966 :                 *prop_len = ZSTR_LEN(name) - class_name_len - 2;
    1363             :         }
    1364        2136 :         return SUCCESS;
    1365             : }
    1366             : /* }}} */
    1367             : 
    1368       30966 : static zend_constant *zend_lookup_reserved_const(const char *name, size_t len) /* {{{ */
    1369             : {
    1370       30966 :         zend_constant *c = zend_hash_find_ptr_lc(EG(zend_constants), name, len);
    1371       30966 :         if (c && !(c->flags & CONST_CS) && (c->flags & CONST_CT_SUBST)) {
    1372       23019 :                 return c;
    1373             :         }
    1374        7947 :         return NULL;
    1375             : }
    1376             : /* }}} */
    1377             : 
    1378       92055 : static zend_bool zend_try_ct_eval_const(zval *zv, zend_string *name, zend_bool is_fully_qualified) /* {{{ */
    1379             : {
    1380             :         zend_constant *c;
    1381             : 
    1382             :         /* Substitute case-sensitive (or lowercase) constants */
    1383      184110 :         c = zend_hash_find_ptr(EG(zend_constants), name);
    1384      243338 :         if (c && (
    1385      136825 :               ((c->flags & CONST_PERSISTENT) && !(CG(compiler_options) & ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION))
    1386       14458 :            || (Z_TYPE(c->value) < IS_OBJECT && !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION))
    1387             :         )) {
    1388       61302 :                 ZVAL_DUP(zv, &c->value);
    1389       61302 :                 return 1;
    1390             :         }
    1391             : 
    1392             :         {
    1393             :                 /* Substitute true, false and null (including unqualified usage in namespaces) */
    1394       30753 :                 const char *lookup_name = ZSTR_VAL(name);
    1395       30753 :                 size_t lookup_len = ZSTR_LEN(name);
    1396             : 
    1397       30753 :                 if (!is_fully_qualified) {
    1398       30599 :                         zend_get_unqualified_name(name, &lookup_name, &lookup_len);
    1399             :                 }
    1400             : 
    1401       30753 :                 c = zend_lookup_reserved_const(lookup_name, lookup_len);
    1402       30753 :                 if (c) {
    1403       23018 :                         ZVAL_DUP(zv, &c->value);
    1404       23018 :                         return 1;
    1405             :                 }
    1406             :         }
    1407             : 
    1408        7735 :         return 0;
    1409             : }
    1410             : /* }}} */
    1411             : 
    1412        4775 : static inline zend_bool zend_is_scope_known() /* {{{ */
    1413             : {
    1414        4775 :         if (CG(active_op_array)->fn_flags & ZEND_ACC_CLOSURE) {
    1415             :                 /* Closures can be rebound to a different scope */
    1416          21 :                 return 0;
    1417             :         }
    1418             : 
    1419        4754 :         if (!CG(active_class_entry)) {
    1420             :                 /* The scope is known if we're in a free function (no scope), but not if we're in
    1421             :                  * a file/eval (which inherits including/eval'ing scope). */
    1422          16 :                 return CG(active_op_array)->function_name != NULL;
    1423             :         }
    1424             : 
    1425             :         /* For traits self etc refers to the using class, not the trait itself */
    1426        4738 :         return (CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) == 0;
    1427             : }
    1428             : /* }}} */
    1429             : 
    1430       10928 : static inline zend_bool class_name_refers_to_active_ce(zend_string *class_name, uint32_t fetch_type) /* {{{ */
    1431             : {
    1432       10928 :         if (!CG(active_class_entry)) {
    1433        3787 :                 return 0;
    1434             :         }
    1435        7141 :         if (fetch_type == ZEND_FETCH_CLASS_SELF && zend_is_scope_known()) {
    1436         109 :                 return 1;
    1437             :         }
    1438       14073 :         return fetch_type == ZEND_FETCH_CLASS_DEFAULT
    1439        7041 :                 && zend_string_equals_ci(class_name, CG(active_class_entry)->name);
    1440             : }
    1441             : /* }}} */
    1442             : 
    1443       48657 : uint32_t zend_get_class_fetch_type(zend_string *name) /* {{{ */
    1444             : {
    1445       48657 :         if (zend_string_equals_literal_ci(name, "self")) {
    1446        3931 :                 return ZEND_FETCH_CLASS_SELF;
    1447       44726 :         } else if (zend_string_equals_literal_ci(name, "parent")) {
    1448        2321 :                 return ZEND_FETCH_CLASS_PARENT;
    1449       42405 :         } else if (zend_string_equals_literal_ci(name, "static")) {
    1450         110 :                 return ZEND_FETCH_CLASS_STATIC;
    1451             :         } else {
    1452       42295 :                 return ZEND_FETCH_CLASS_DEFAULT;
    1453             :         }
    1454             : }
    1455             : /* }}} */
    1456             : 
    1457        6050 : static uint32_t zend_get_class_fetch_type_ast(zend_ast *name_ast) /* {{{ */
    1458             : {
    1459             :         /* Fully qualified names are always default refs */
    1460        6050 :         if (name_ast->attr == ZEND_NAME_FQ) {
    1461          87 :                 return ZEND_FETCH_CLASS_DEFAULT;
    1462             :         }
    1463             : 
    1464        5963 :         return zend_get_class_fetch_type(zend_ast_get_str(name_ast));
    1465             : }
    1466             : /* }}} */
    1467             : 
    1468        6163 : static void zend_ensure_valid_class_fetch_type(uint32_t fetch_type) /* {{{ */
    1469             : {
    1470        6163 :         if (fetch_type != ZEND_FETCH_CLASS_DEFAULT && !CG(active_class_entry) && zend_is_scope_known()) {
    1471           3 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use \"%s\" when no class scope is active",
    1472             :                         fetch_type == ZEND_FETCH_CLASS_SELF ? "self" :
    1473             :                         fetch_type == ZEND_FETCH_CLASS_PARENT ? "parent" : "static");
    1474             :         }
    1475        6160 : }
    1476             : /* }}} */
    1477             : 
    1478       11316 : static zend_bool zend_try_compile_const_expr_resolve_class_name(zval *zv, zend_ast *class_ast, zend_ast *name_ast, zend_bool constant) /* {{{ */
    1479             : {
    1480             :         uint32_t fetch_type;
    1481             : 
    1482       11316 :         if (name_ast->kind != ZEND_AST_ZVAL) {
    1483           0 :                 return 0;
    1484             :         }
    1485             : 
    1486       11656 :         if (!zend_string_equals_literal_ci(zend_ast_get_str(name_ast), "class")) {
    1487       11242 :                 return 0;
    1488             :         }
    1489             : 
    1490          74 :         if (class_ast->kind != ZEND_AST_ZVAL) {
    1491           0 :                 zend_error_noreturn(E_COMPILE_ERROR,
    1492             :                         "Dynamic class names are not allowed in compile-time ::class fetch");
    1493             :         }
    1494             : 
    1495          74 :         fetch_type = zend_get_class_fetch_type(zend_ast_get_str(class_ast));
    1496          74 :         zend_ensure_valid_class_fetch_type(fetch_type);
    1497             : 
    1498          74 :         switch (fetch_type) {
    1499             :                 case ZEND_FETCH_CLASS_SELF:
    1500          21 :                         if (constant || (CG(active_class_entry) && zend_is_scope_known())) {
    1501           5 :                                 ZVAL_STR_COPY(zv, CG(active_class_entry)->name);
    1502             :                         } else {
    1503          11 :                                 ZVAL_NULL(zv);
    1504             :                         }
    1505          16 :                         return 1;
    1506             :                 case ZEND_FETCH_CLASS_STATIC:
    1507             :                 case ZEND_FETCH_CLASS_PARENT:
    1508          27 :                         if (constant) {
    1509           4 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    1510             :                                         "%s::class cannot be used for compile-time class name resolution",
    1511             :                                         fetch_type == ZEND_FETCH_CLASS_STATIC ? "static" : "parent"
    1512             :                                 );
    1513             :                         } else {
    1514          23 :                                 ZVAL_NULL(zv);
    1515             :                         }
    1516          23 :                         return 1;
    1517             :                 case ZEND_FETCH_CLASS_DEFAULT:
    1518          31 :                         ZVAL_STR(zv, zend_resolve_class_name_ast(class_ast));
    1519          31 :                         return 1;
    1520             :                 EMPTY_SWITCH_DEFAULT_CASE()
    1521             :         }
    1522           0 : }
    1523             : /* }}} */
    1524             : 
    1525       10928 : static zend_bool zend_try_ct_eval_class_const(zval *zv, zend_string *class_name, zend_string *name) /* {{{ */
    1526             : {
    1527       10928 :         uint32_t fetch_type = zend_get_class_fetch_type(class_name);
    1528             :         zend_class_constant *cc;
    1529             :         zval *c;
    1530             : 
    1531       10928 :         if (class_name_refers_to_active_ce(class_name, fetch_type)) {
    1532         240 :                 cc = zend_hash_find_ptr(&CG(active_class_entry)->constants_table, name);
    1533       21195 :         } else if (fetch_type == ZEND_FETCH_CLASS_DEFAULT && !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION)) {
    1534       10417 :                 zend_class_entry *ce = zend_hash_find_ptr_lc(CG(class_table), ZSTR_VAL(class_name), ZSTR_LEN(class_name));
    1535       10417 :                 if (ce) {
    1536       20774 :                         cc = zend_hash_find_ptr(&ce->constants_table, name);
    1537             :                 } else {
    1538          30 :                         return 0;
    1539             :                 }
    1540             :         } else {
    1541         391 :                 return 0;
    1542             :         }
    1543             : 
    1544       10507 :         if (CG(compiler_options) & ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION) {
    1545          12 :                 return 0;
    1546             :         }
    1547             : 
    1548       10495 :         if (!cc || !zend_verify_const_access(cc, CG(active_class_entry))) {
    1549          26 :                 return 0;
    1550             :         }
    1551             : 
    1552       10469 :         c = &cc->value;
    1553             : 
    1554             :         /* Substitute case-sensitive (or lowercase) persistent class constants */
    1555       10469 :         if (Z_TYPE_P(c) < IS_OBJECT) {
    1556       10446 :                 ZVAL_DUP(zv, c);
    1557       10446 :                 return 1;
    1558             :         }
    1559             : 
    1560          23 :         return 0;
    1561             : }
    1562             : /* }}} */
    1563             : 
    1564          95 : static void zend_add_to_list(void *result, void *item) /* {{{ */
    1565             : {
    1566          95 :         void** list = *(void**)result;
    1567          95 :         size_t n = 0;
    1568             : 
    1569          95 :         if (list) {
    1570         127 :                 while (list[n]) {
    1571          67 :                         n++;
    1572             :                 }
    1573             :         }
    1574             : 
    1575          95 :         list = erealloc(list, sizeof(void*) * (n+2));
    1576             : 
    1577          95 :         list[n]   = item;
    1578          95 :         list[n+1] = NULL;
    1579             : 
    1580          95 :         *(void**)result = list;
    1581          95 : }
    1582             : /* }}} */
    1583             : 
    1584       42095 : void zend_do_extended_info(void) /* {{{ */
    1585             : {
    1586             :         zend_op *opline;
    1587             : 
    1588       42095 :         if (!(CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO)) {
    1589       42095 :                 return;
    1590             :         }
    1591             : 
    1592           0 :         opline = get_next_op(CG(active_op_array));
    1593             : 
    1594           0 :         opline->opcode = ZEND_EXT_STMT;
    1595           0 :         SET_UNUSED(opline->op1);
    1596           0 :         SET_UNUSED(opline->op2);
    1597             : }
    1598             : /* }}} */
    1599             : 
    1600      358700 : void zend_do_extended_fcall_begin(void) /* {{{ */
    1601             : {
    1602             :         zend_op *opline;
    1603             : 
    1604      358700 :         if (!(CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO)) {
    1605      358700 :                 return;
    1606             :         }
    1607             : 
    1608           0 :         opline = get_next_op(CG(active_op_array));
    1609             : 
    1610           0 :         opline->opcode = ZEND_EXT_FCALL_BEGIN;
    1611           0 :         SET_UNUSED(opline->op1);
    1612           0 :         SET_UNUSED(opline->op2);
    1613             : }
    1614             : /* }}} */
    1615             : 
    1616      358684 : void zend_do_extended_fcall_end(void) /* {{{ */
    1617             : {
    1618             :         zend_op *opline;
    1619             : 
    1620      358684 :         if (!(CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO)) {
    1621      358684 :                 return;
    1622             :         }
    1623             : 
    1624           0 :         opline = get_next_op(CG(active_op_array));
    1625             : 
    1626           0 :         opline->opcode = ZEND_EXT_FCALL_END;
    1627           0 :         SET_UNUSED(opline->op1);
    1628           0 :         SET_UNUSED(opline->op2);
    1629             : }
    1630             : /* }}} */
    1631             : 
    1632       22964 : zend_bool zend_is_auto_global_str(char *name, size_t len) /* {{{ */ {
    1633             :         zend_auto_global *auto_global;
    1634             : 
    1635       45928 :         if ((auto_global = zend_hash_str_find_ptr(CG(auto_globals), name, len)) != NULL) {
    1636       22957 :                 if (auto_global->armed) {
    1637       22942 :                         auto_global->armed = auto_global->auto_global_callback(auto_global->name);
    1638             :                 }
    1639       22957 :                 return 1;
    1640             :         }
    1641           7 :         return 0;
    1642             : }
    1643             : /* }}} */
    1644             : 
    1645      803355 : zend_bool zend_is_auto_global(zend_string *name) /* {{{ */
    1646             : {
    1647             :         zend_auto_global *auto_global;
    1648             : 
    1649     1606710 :         if ((auto_global = zend_hash_find_ptr(CG(auto_globals), name)) != NULL) {
    1650       35748 :                 if (auto_global->armed) {
    1651        1634 :                         auto_global->armed = auto_global->auto_global_callback(auto_global->name);
    1652             :                 }
    1653       35748 :                 return 1;
    1654             :         }
    1655      767607 :         return 0;
    1656             : }
    1657             : /* }}} */
    1658             : 
    1659      211077 : int zend_register_auto_global(zend_string *name, zend_bool jit, zend_auto_global_callback auto_global_callback) /* {{{ */
    1660             : {
    1661             :         zend_auto_global auto_global;
    1662             :         int retval;
    1663             : 
    1664      211077 :         auto_global.name = zend_new_interned_string(name);
    1665      211077 :         auto_global.auto_global_callback = auto_global_callback;
    1666      211077 :         auto_global.jit = jit;
    1667             : 
    1668      422154 :         retval = zend_hash_add_mem(CG(auto_globals), auto_global.name, &auto_global, sizeof(zend_auto_global)) != NULL ? SUCCESS : FAILURE;
    1669             : 
    1670             :         zend_string_release(name);
    1671      211077 :         return retval;
    1672             : }
    1673             : /* }}} */
    1674             : 
    1675       23407 : ZEND_API void zend_activate_auto_globals(void) /* {{{ */
    1676             : {
    1677             :         zend_auto_global *auto_global;
    1678             : 
    1679      444733 :         ZEND_HASH_FOREACH_PTR(CG(auto_globals), auto_global) {
    1680      210663 :                 if (auto_global->jit) {
    1681       93622 :                         auto_global->armed = 1;
    1682      117041 :                 } else if (auto_global->auto_global_callback) {
    1683       93634 :                         auto_global->armed = auto_global->auto_global_callback(auto_global->name);
    1684             :                 } else {
    1685       23407 :                         auto_global->armed = 0;
    1686             :                 }
    1687             :         } ZEND_HASH_FOREACH_END();
    1688       23407 : }
    1689             : /* }}} */
    1690             : 
    1691     5561293 : int zendlex(zend_parser_stack_elem *elem) /* {{{ */
    1692             : {
    1693             :         zval zv;
    1694             :         int retval;
    1695             : 
    1696     5561293 :         if (CG(increment_lineno)) {
    1697       29779 :                 CG(zend_lineno)++;
    1698       29779 :                 CG(increment_lineno) = 0;
    1699             :         }
    1700             : 
    1701             : again:
    1702     8091547 :         ZVAL_UNDEF(&zv);
    1703     8091547 :         retval = lex_scan(&zv);
    1704     8091547 :         if (EG(exception)) {
    1705          14 :                 return T_ERROR;
    1706             :         }
    1707             : 
    1708     8091533 :         switch (retval) {
    1709             :                 case T_COMMENT:
    1710             :                 case T_DOC_COMMENT:
    1711             :                 case T_OPEN_TAG:
    1712             :                 case T_WHITESPACE:
    1713     2530254 :                         goto again;
    1714             : 
    1715             :                 case T_CLOSE_TAG:
    1716       31114 :                         if (LANG_SCNG(yy_text)[LANG_SCNG(yy_leng)-1] != '>') {
    1717       28242 :                                 CG(increment_lineno) = 1;
    1718             :                         }
    1719       31114 :                         retval = ';'; /* implicit ; */
    1720       31114 :                         break;
    1721             :                 case T_OPEN_TAG_WITH_ECHO:
    1722           3 :                         retval = T_ECHO;
    1723             :                         break;
    1724             :         }
    1725     5561279 :         if (Z_TYPE(zv) != IS_UNDEF) {
    1726     1955530 :                 elem->ast = zend_ast_create_zval(&zv);
    1727             :         }
    1728             : 
    1729     5561279 :         return retval;
    1730             : }
    1731             : /* }}} */
    1732             : 
    1733     4534543 : ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers) /* {{{ */
    1734             : {
    1735     4534543 :         zend_bool persistent_hashes = (ce->type == ZEND_INTERNAL_CLASS) ? 1 : 0;
    1736             : 
    1737     4534543 :         ce->refcount = 1;
    1738     4534543 :         ce->ce_flags = ZEND_ACC_CONSTANTS_UPDATED;
    1739             : 
    1740     4534543 :         if (CG(compiler_options) & ZEND_COMPILE_GUARDS) {
    1741           0 :                 ce->ce_flags |= ZEND_ACC_USE_GUARDS;
    1742             :         }
    1743             : 
    1744     4534543 :         ce->default_properties_table = NULL;
    1745     4534543 :         ce->default_static_members_table = NULL;
    1746     4534543 :         zend_hash_init_ex(&ce->properties_info, 8, NULL, (persistent_hashes ? zend_destroy_property_info_internal : NULL), persistent_hashes, 0);
    1747     4534543 :         zend_hash_init_ex(&ce->constants_table, 8, NULL, (persistent_hashes ? zend_destroy_class_constant_internal : NULL), persistent_hashes, 0);
    1748     4534543 :         zend_hash_init_ex(&ce->function_table, 8, NULL, ZEND_FUNCTION_DTOR, persistent_hashes, 0);
    1749             : 
    1750     4534543 :         if (ce->type == ZEND_INTERNAL_CLASS) {
    1751             : #ifdef ZTS
    1752             :                 int n = zend_hash_num_elements(CG(class_table));
    1753             : 
    1754             :                 if (CG(static_members_table) && n >= CG(last_static_member)) {
    1755             :                         /* Support for run-time declaration: dl() */
    1756             :                         CG(last_static_member) = n+1;
    1757             :                         CG(static_members_table) = realloc(CG(static_members_table), (n+1)*sizeof(zval*));
    1758             :                         CG(static_members_table)[n] = NULL;
    1759             :                 }
    1760             :                 ce->static_members_table = (zval*)(zend_intptr_t)n;
    1761             : #else
    1762     4526429 :                 ce->static_members_table = NULL;
    1763             : #endif
    1764             :         } else {
    1765        8114 :                 ce->static_members_table = ce->default_static_members_table;
    1766        8114 :                 ce->info.user.doc_comment = NULL;
    1767             :         }
    1768             : 
    1769     4534543 :         ce->default_properties_count = 0;
    1770     4534543 :         ce->default_static_members_count = 0;
    1771             : 
    1772     4534543 :         if (nullify_handlers) {
    1773        8114 :                 ce->constructor = NULL;
    1774        8114 :                 ce->destructor = NULL;
    1775        8114 :                 ce->clone = NULL;
    1776        8114 :                 ce->__get = NULL;
    1777        8114 :                 ce->__set = NULL;
    1778        8114 :                 ce->__unset = NULL;
    1779        8114 :                 ce->__isset = NULL;
    1780        8114 :                 ce->__call = NULL;
    1781        8114 :                 ce->__callstatic = NULL;
    1782        8114 :                 ce->__tostring = NULL;
    1783        8114 :                 ce->create_object = NULL;
    1784        8114 :                 ce->get_iterator = NULL;
    1785        8114 :                 ce->iterator_funcs.funcs = NULL;
    1786        8114 :                 ce->interface_gets_implemented = NULL;
    1787        8114 :                 ce->get_static_method = NULL;
    1788        8114 :                 ce->parent = NULL;
    1789        8114 :                 ce->num_interfaces = 0;
    1790        8114 :                 ce->interfaces = NULL;
    1791        8114 :                 ce->num_traits = 0;
    1792        8114 :                 ce->traits = NULL;
    1793        8114 :                 ce->trait_aliases = NULL;
    1794        8114 :                 ce->trait_precedences = NULL;
    1795        8114 :                 ce->serialize = NULL;
    1796        8114 :                 ce->unserialize = NULL;
    1797        8114 :                 ce->serialize_func = NULL;
    1798        8114 :                 ce->unserialize_func = NULL;
    1799        8114 :                 ce->__debugInfo = NULL;
    1800        8114 :                 if (ce->type == ZEND_INTERNAL_CLASS) {
    1801           0 :                         ce->info.internal.module = NULL;
    1802           0 :                         ce->info.internal.builtin_functions = NULL;
    1803             :                 }
    1804             :         }
    1805     4534543 : }
    1806             : /* }}} */
    1807             : 
    1808           0 : ZEND_API zend_string *zend_get_compiled_variable_name(const zend_op_array *op_array, uint32_t var) /* {{{ */
    1809             : {
    1810           0 :         return op_array->vars[EX_VAR_TO_NUM(var)];
    1811             : }
    1812             : /* }}} */
    1813             : 
    1814         452 : zend_ast *zend_ast_append_str(zend_ast *left_ast, zend_ast *right_ast) /* {{{ */
    1815             : {
    1816         452 :         zval *left_zv = zend_ast_get_zval(left_ast);
    1817         452 :         zend_string *left = Z_STR_P(left_zv);
    1818         452 :         zend_string *right = zend_ast_get_str(right_ast);
    1819             : 
    1820             :         zend_string *result;
    1821         452 :         size_t left_len = ZSTR_LEN(left);
    1822         452 :         size_t len = left_len + ZSTR_LEN(right) + 1; /* left\right */
    1823             : 
    1824         452 :         result = zend_string_extend(left, len, 0);
    1825         452 :         ZSTR_VAL(result)[left_len] = '\\';
    1826         452 :         memcpy(&ZSTR_VAL(result)[left_len + 1], ZSTR_VAL(right), ZSTR_LEN(right));
    1827         452 :         ZSTR_VAL(result)[len] = '\0';
    1828             :         zend_string_release(right);
    1829             : 
    1830         452 :         ZVAL_STR(left_zv, result);
    1831         452 :         return left_ast;
    1832             : }
    1833             : /* }}} */
    1834             : 
    1835      212256 : void zend_verify_namespace(void) /* {{{ */
    1836             : {
    1837      212256 :         if (FC(has_bracketed_namespaces) && !FC(in_namespace)) {
    1838           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "No code may exist outside of namespace {}");
    1839             :         }
    1840      212255 : }
    1841             : /* }}} */
    1842             : 
    1843             : /* {{{ zend_dirname
    1844             :    Returns directory name component of path */
    1845       29559 : ZEND_API size_t zend_dirname(char *path, size_t len)
    1846             : {
    1847       29559 :         register char *end = path + len - 1;
    1848       29559 :         unsigned int len_adjust = 0;
    1849             : 
    1850             : #ifdef ZEND_WIN32
    1851             :         /* Note that on Win32 CWD is per drive (heritage from CP/M).
    1852             :          * This means dirname("c:foo") maps to "c:." or "c:" - which means CWD on C: drive.
    1853             :          */
    1854             :         if ((2 <= len) && isalpha((int)((unsigned char *)path)[0]) && (':' == path[1])) {
    1855             :                 /* Skip over the drive spec (if any) so as not to change */
    1856             :                 path += 2;
    1857             :                 len_adjust += 2;
    1858             :                 if (2 == len) {
    1859             :                         /* Return "c:" on Win32 for dirname("c:").
    1860             :                          * It would be more consistent to return "c:."
    1861             :                          * but that would require making the string *longer*.
    1862             :                          */
    1863             :                         return len;
    1864             :                 }
    1865             :         }
    1866             : #elif defined(NETWARE)
    1867             :         /*
    1868             :          * Find the first occurrence of : from the left
    1869             :          * move the path pointer to the position just after :
    1870             :          * increment the len_adjust to the length of path till colon character(inclusive)
    1871             :          * If there is no character beyond : simple return len
    1872             :          */
    1873             :         char *colonpos = NULL;
    1874             :         colonpos = strchr(path, ':');
    1875             :         if (colonpos != NULL) {
    1876             :                 len_adjust = ((colonpos - path) + 1);
    1877             :                 path += len_adjust;
    1878             :                 if (len_adjust == len) {
    1879             :                         return len;
    1880             :                 }
    1881             :         }
    1882             : #endif
    1883             : 
    1884       29559 :         if (len == 0) {
    1885             :                 /* Illegal use of this function */
    1886          36 :                 return 0;
    1887             :         }
    1888             : 
    1889             :         /* Strip trailing slashes */
    1890       59139 :         while (end >= path && IS_SLASH_P(end)) {
    1891          93 :                 end--;
    1892             :         }
    1893       29523 :         if (end < path) {
    1894             :                 /* The path only contained slashes */
    1895          13 :                 path[0] = DEFAULT_SLASH;
    1896          13 :                 path[1] = '\0';
    1897          13 :                 return 1 + len_adjust;
    1898             :         }
    1899             : 
    1900             :         /* Strip filename */
    1901      664851 :         while (end >= path && !IS_SLASH_P(end)) {
    1902      605831 :                 end--;
    1903             :         }
    1904       29510 :         if (end < path) {
    1905             :                 /* No slash found, therefore return '.' */
    1906             : #ifdef NETWARE
    1907             :                 if (len_adjust == 0) {
    1908             :                         path[0] = '.';
    1909             :                         path[1] = '\0';
    1910             :                         return 1; /* only one character */
    1911             :                 } else {
    1912             :                         path[0] = '\0';
    1913             :                         return len_adjust;
    1914             :                 }
    1915             : #else
    1916         174 :                 path[0] = '.';
    1917         174 :                 path[1] = '\0';
    1918         174 :                 return 1 + len_adjust;
    1919             : #endif
    1920             :         }
    1921             : 
    1922             :         /* Strip slashes which came before the file name */
    1923       88023 :         while (end >= path && IS_SLASH_P(end)) {
    1924       29351 :                 end--;
    1925             :         }
    1926       29336 :         if (end < path) {
    1927          26 :                 path[0] = DEFAULT_SLASH;
    1928          26 :                 path[1] = '\0';
    1929          26 :                 return 1 + len_adjust;
    1930             :         }
    1931       29310 :         *(end+1) = '\0';
    1932             : 
    1933       29310 :         return (size_t)(end + 1 - path) + len_adjust;
    1934             : }
    1935             : /* }}} */
    1936             : 
    1937      138928 : static void zend_adjust_for_fetch_type(zend_op *opline, uint32_t type) /* {{{ */
    1938             : {
    1939      138928 :         zend_uchar factor = (opline->opcode == ZEND_FETCH_STATIC_PROP_R) ? 1 : 3;
    1940             :         
    1941      138928 :         if (opline->opcode == ZEND_FETCH_THIS) {
    1942         367 :                 return;
    1943             :         }
    1944             : 
    1945      138561 :         switch (type & BP_VAR_MASK) {
    1946             :                 case BP_VAR_R:
    1947       60035 :                         return;
    1948             :                 case BP_VAR_W:
    1949       70123 :                         opline->opcode += 1 * factor;
    1950       70123 :                         return;
    1951             :                 case BP_VAR_RW:
    1952        1188 :                         opline->opcode += 2 * factor;
    1953        1188 :                         return;
    1954             :                 case BP_VAR_IS:
    1955        4690 :                         opline->opcode += 3 * factor;
    1956        4690 :                         return;
    1957             :                 case BP_VAR_FUNC_ARG:
    1958        2440 :                         opline->opcode += 4 * factor;
    1959        2440 :                         opline->extended_value |= type >> BP_VAR_SHIFT;
    1960        2440 :                         return;
    1961             :                 case BP_VAR_UNSET:
    1962          85 :                         opline->opcode += 5 * factor;
    1963          85 :                         return;
    1964             :                 EMPTY_SWITCH_DEFAULT_CASE()
    1965             :         }
    1966             : }
    1967             : /* }}} */
    1968             : 
    1969      721403 : static inline void zend_make_var_result(znode *result, zend_op *opline) /* {{{ */
    1970             : {
    1971      721403 :         opline->result_type = IS_VAR;
    1972      721403 :         opline->result.var = get_temporary_variable(CG(active_op_array));
    1973      721403 :         GET_NODE(result, opline->result);
    1974      721403 : }
    1975             : /* }}} */
    1976             : 
    1977      203479 : static inline void zend_make_tmp_result(znode *result, zend_op *opline) /* {{{ */
    1978             : {
    1979      203479 :         opline->result_type = IS_TMP_VAR;
    1980      203479 :         opline->result.var = get_temporary_variable(CG(active_op_array));
    1981      203479 :         GET_NODE(result, opline->result);
    1982      203479 : }
    1983             : /* }}} */
    1984             : 
    1985       30111 : static void zend_find_live_range(zend_op *opline, zend_uchar type, uint32_t var) /* {{{ */
    1986             : {
    1987       30111 :         zend_op *def = opline;
    1988             : 
    1989      166509 :         while (def != CG(active_op_array)->opcodes) {
    1990      136382 :                 def--;
    1991      136382 :                 if (def->result_type == type && def->result.var == var) {
    1992       86740 :                         if (def->opcode == ZEND_ADD_ARRAY_ELEMENT ||
    1993       30095 :                             def->opcode == ZEND_ROPE_ADD) {
    1994             :                             /* not a real definition */
    1995       26550 :                                 continue;
    1996      120380 :                         } else if (def->opcode == ZEND_JMPZ_EX ||
    1997       30095 :                                    def->opcode == ZEND_JMPNZ_EX ||
    1998       30095 :                                    def->opcode == ZEND_BOOL ||
    1999       30095 :                                    def->opcode == ZEND_BOOL_NOT) {
    2000             :                                 /* result IS_BOOL, it does't have to be destroyed */
    2001             :                                 break;
    2002      150475 :                         } else if (def->opcode == ZEND_DECLARE_CLASS ||
    2003       30095 :                                    def->opcode == ZEND_DECLARE_INHERITED_CLASS ||
    2004       30095 :                                    def->opcode == ZEND_DECLARE_INHERITED_CLASS_DELAYED ||
    2005       30095 :                                    def->opcode == ZEND_DECLARE_ANON_CLASS ||
    2006       30095 :                                    def->opcode == ZEND_DECLARE_ANON_INHERITED_CLASS) {
    2007             :                                 /* classes don't have to be destroyed */
    2008             :                                 break;
    2009       30095 :                         } else if (def->opcode == ZEND_FAST_CALL) {
    2010             :                                 /* fast_calls don't have to be destroyed */
    2011           0 :                                 break;
    2012       30095 :                         } else if (def->opcode == ZEND_NEW) {
    2013             :                                 /* Objects created via ZEND_NEW are only fully initialized
    2014             :                                  * after the DO_FCALL (constructor call) */
    2015       15437 :                                 def = CG(active_op_array)->opcodes + def->op2.opline_num - 1;
    2016       15437 :                                 if (def + 1 == opline) {
    2017       15281 :                                         break;
    2018             :                                 }
    2019             :                         }
    2020             : 
    2021       29628 :                 zend_end_live_range(CG(active_op_array),
    2022             :                                 zend_start_live_range_ex(CG(active_op_array),
    2023       14814 :                                         def + 1 - CG(active_op_array)->opcodes),
    2024       14814 :                                 opline - CG(active_op_array)->opcodes,
    2025             :                                 ZEND_LIVE_TMPVAR, var);
    2026       14814 :                     break;
    2027             :                 }
    2028             :         }
    2029       30111 : }
    2030             : /* }}} */
    2031             : 
    2032             : static zend_always_inline int zend_is_def_range(zend_op *opline, zend_uchar type, uint32_t var) /* {{{ */
    2033             : {
    2034             :         while (1) {
    2035      673348 :                 if (opline->result_type == type && opline->result.var == var) {
    2036     1230725 :                         return opline->opcode != ZEND_ADD_ARRAY_ELEMENT &&
    2037      613631 :                                 opline->opcode != ZEND_ROPE_ADD;
    2038       56254 :                 } else if (opline->opcode == ZEND_OP_DATA) {
    2039         220 :                         return (opline-1)->result_type == type &&
    2040          96 :                                 (opline-1)->result.var == var;
    2041      359760 :                 } else if (opline->opcode == ZEND_END_SILENCE ||
    2042       50605 :                            opline->opcode == ZEND_NOP ||
    2043       50605 :                        opline->opcode == ZEND_EXT_NOP ||
    2044       50605 :                            opline->opcode == ZEND_EXT_STMT ||
    2045       50605 :                            opline->opcode == ZEND_EXT_FCALL_BEGIN ||
    2046       50605 :                            opline->opcode == ZEND_EXT_FCALL_END ||
    2047       50605 :                            opline->opcode == ZEND_TICKS) {
    2048        5525 :                         opline--;
    2049             :                 } else {
    2050       50605 :                         return 0;
    2051             :                 }
    2052             :         }
    2053             : }
    2054             : /* }}} */
    2055             : 
    2056     2422061 : static void zend_check_live_ranges(zend_op *opline) /* {{{ */
    2057             : {
    2058     2951620 :         if ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) &&
    2059      529559 :                 !zend_is_def_range(opline - 1, opline->op1_type, opline->op1.var)) {
    2060             : 
    2061       38641 :                 if (opline->opcode == ZEND_OP_DATA) {
    2062        7218 :                         if (!zend_is_def_range(opline - 2, opline->op1_type, opline->op1.var)) {
    2063        2062 :                                 zend_find_live_range(opline - 1, opline->op1_type, opline->op1.var);
    2064             :                         }
    2065      244859 :                 } else if (opline->opcode == ZEND_INIT_STATIC_METHOD_CALL ||
    2066       35031 :                            opline->opcode == ZEND_NEW ||
    2067       35031 :                            opline->opcode == ZEND_FETCH_CLASS_CONSTANT ||
    2068       35031 :                            opline->opcode == ZEND_ADD_INTERFACE ||
    2069       34977 :                            opline->opcode == ZEND_ADD_TRAIT ||
    2070       34977 :                            opline->opcode == ZEND_BIND_TRAITS ||
    2071       34780 :                            opline->opcode == ZEND_VERIFY_ABSTRACT_CLASS) {
    2072             :                         /* classes don't have to be destroyed */
    2073       34453 :                 } else if (opline->opcode == ZEND_FAST_RET) {
    2074             :                         /* fast_calls don't have to be destroyed */
    2075      247410 :                 } else if (opline->opcode == ZEND_CASE ||
    2076       34104 :                            opline->opcode == ZEND_FE_FETCH_R ||
    2077       34104 :                            opline->opcode == ZEND_FE_FETCH_RW ||
    2078       34104 :                                opline->opcode == ZEND_FE_FREE ||
    2079       22123 :                                opline->opcode == ZEND_ROPE_ADD ||
    2080       22123 :                                opline->opcode == ZEND_ROPE_END ||
    2081       22123 :                                opline->opcode == ZEND_END_SILENCE ||
    2082       14937 :                                opline->opcode == ZEND_FETCH_LIST ||
    2083       14681 :                                opline->opcode == ZEND_VERIFY_RETURN_TYPE ||
    2084       14658 :                                opline->opcode == ZEND_BIND_LEXICAL) {
    2085             :                         /* these opcodes are handled separately */
    2086             :                 } else {
    2087       14647 :                         zend_find_live_range(opline, opline->op1_type, opline->op1.var);
    2088             :                 }
    2089             :         }
    2090             : 
    2091     2556716 :         if ((opline->op2_type & (IS_VAR|IS_TMP_VAR)) &&
    2092      134655 :                 !zend_is_def_range(opline - 1, opline->op2_type, opline->op2.var)) {
    2093             : 
    2094       13402 :                 if (opline->opcode == ZEND_OP_DATA) {
    2095           0 :                         if (!zend_is_def_range(opline - 2, opline->op2_type, opline->op2.var)) {
    2096           0 :                                 zend_find_live_range(opline-1, opline->op2_type, opline->op2.var);
    2097             :                         }
    2098      120618 :                 } else if (opline->opcode == ZEND_FETCH_STATIC_PROP_R ||
    2099       13402 :                            opline->opcode == ZEND_FETCH_STATIC_PROP_W ||
    2100       13402 :                            opline->opcode == ZEND_FETCH_STATIC_PROP_RW ||
    2101       13402 :                            opline->opcode == ZEND_FETCH_STATIC_PROP_IS ||
    2102       13402 :                            opline->opcode == ZEND_FETCH_STATIC_PROP_FUNC_ARG ||
    2103       13402 :                            opline->opcode == ZEND_FETCH_STATIC_PROP_UNSET ||
    2104       13402 :                            opline->opcode == ZEND_UNSET_STATIC_PROP ||
    2105       13402 :                            opline->opcode == ZEND_ISSET_ISEMPTY_STATIC_PROP ||
    2106       13402 :                            opline->opcode == ZEND_INSTANCEOF) {
    2107             :                         /* classes don't have to be destroyed */
    2108             :                 } else {
    2109       13402 :                         zend_find_live_range(opline, opline->op2_type, opline->op2.var);
    2110             :                 }
    2111             :         }
    2112     2422061 : }
    2113             : /* }}} */
    2114             : 
    2115     2053019 : static zend_op *zend_emit_op(znode *result, zend_uchar opcode, znode *op1, znode *op2) /* {{{ */
    2116             : {
    2117     2053019 :         zend_op *opline = get_next_op(CG(active_op_array));
    2118     2053019 :         opline->opcode = opcode;
    2119             : 
    2120     2053019 :         if (op1 == NULL) {
    2121      803042 :                 SET_UNUSED(opline->op1);
    2122             :         } else {
    2123     1249977 :                 SET_NODE(opline->op1, op1);
    2124             :         }
    2125             : 
    2126     2053019 :         if (op2 == NULL) {
    2127     1514158 :                 SET_UNUSED(opline->op2);
    2128             :         } else {
    2129      538861 :                 SET_NODE(opline->op2, op2);
    2130             :         }
    2131             : 
    2132     2053019 :         zend_check_live_ranges(opline);
    2133             : 
    2134     2053019 :         if (result) {
    2135      554800 :                 zend_make_var_result(result, opline);
    2136             :         }
    2137     2053019 :         return opline;
    2138             : }
    2139             : /* }}} */
    2140             : 
    2141      198443 : static zend_op *zend_emit_op_tmp(znode *result, zend_uchar opcode, znode *op1, znode *op2) /* {{{ */
    2142             : {
    2143      198443 :         zend_op *opline = get_next_op(CG(active_op_array));
    2144      198443 :         opline->opcode = opcode;
    2145             : 
    2146      198443 :         if (op1 == NULL) {
    2147       13681 :                 SET_UNUSED(opline->op1);
    2148             :         } else {
    2149      184762 :                 SET_NODE(opline->op1, op1);
    2150             :         }
    2151             : 
    2152      198443 :         if (op2 == NULL) {
    2153      100189 :                 SET_UNUSED(opline->op2);
    2154             :         } else {
    2155       98254 :                 SET_NODE(opline->op2, op2);
    2156             :         }
    2157             : 
    2158      198443 :         zend_check_live_ranges(opline);
    2159             : 
    2160      198443 :         if (result) {
    2161      198202 :                 zend_make_tmp_result(result, opline);
    2162             :         }
    2163             : 
    2164      198443 :         return opline;
    2165             : }
    2166             : /* }}} */
    2167             : 
    2168          31 : static void zend_emit_tick(void) /* {{{ */
    2169             : {
    2170             :         zend_op *opline;
    2171             : 
    2172             :         /* This prevents a double TICK generated by the parser statement of "declare()" */
    2173          31 :         if (CG(active_op_array)->last && CG(active_op_array)->opcodes[CG(active_op_array)->last - 1].opcode == ZEND_TICKS) {
    2174           1 :                 return;
    2175             :         }
    2176             :         
    2177          30 :         opline = get_next_op(CG(active_op_array));
    2178             : 
    2179          30 :         opline->opcode = ZEND_TICKS;
    2180          30 :         SET_UNUSED(opline->op1);
    2181          30 :         SET_UNUSED(opline->op2);
    2182          30 :         opline->extended_value = FC(declarables).ticks;
    2183             : }
    2184             : /* }}} */
    2185             : 
    2186       11608 : static inline zend_op *zend_emit_op_data(znode *value) /* {{{ */
    2187             : {
    2188       11608 :         return zend_emit_op(NULL, ZEND_OP_DATA, value, NULL);
    2189             : }
    2190             : /* }}} */
    2191             : 
    2192       68599 : static inline uint32_t zend_emit_jump(uint32_t opnum_target) /* {{{ */
    2193             : {
    2194       68599 :         uint32_t opnum = get_next_op_number(CG(active_op_array));
    2195       68599 :         zend_op *opline = zend_emit_op(NULL, ZEND_JMP, NULL, NULL);
    2196       68599 :         opline->op1.opline_num = opnum_target;
    2197       68599 :         return opnum;
    2198             : }
    2199             : /* }}} */
    2200             : 
    2201      114164 : static inline uint32_t zend_emit_cond_jump(zend_uchar opcode, znode *cond, uint32_t opnum_target) /* {{{ */
    2202             : {
    2203      114164 :         uint32_t opnum = get_next_op_number(CG(active_op_array));
    2204      114164 :         zend_op *opline = zend_emit_op(NULL, opcode, cond, NULL);
    2205      114164 :         opline->op2.opline_num = opnum_target;
    2206      114164 :         return opnum;
    2207             : }
    2208             : /* }}} */
    2209             : 
    2210      180154 : static inline void zend_update_jump_target(uint32_t opnum_jump, uint32_t opnum_target) /* {{{ */
    2211             : {
    2212      180154 :         zend_op *opline = &CG(active_op_array)->opcodes[opnum_jump];
    2213      180154 :         switch (opline->opcode) {
    2214             :                 case ZEND_JMP:
    2215       56774 :                         opline->op1.opline_num = opnum_target;
    2216       56774 :                         break;
    2217             :                 case ZEND_JMPZ:
    2218             :                 case ZEND_JMPNZ:
    2219             :                 case ZEND_JMPZ_EX:
    2220             :                 case ZEND_JMPNZ_EX:
    2221             :                 case ZEND_JMP_SET:
    2222      123380 :                         opline->op2.opline_num = opnum_target;
    2223             :                         break;
    2224             :                 EMPTY_SWITCH_DEFAULT_CASE()
    2225             :         }
    2226      180154 : }
    2227             : /* }}} */
    2228             : 
    2229      178083 : static inline void zend_update_jump_target_to_next(uint32_t opnum_jump) /* {{{ */
    2230             : {
    2231      178083 :         zend_update_jump_target(opnum_jump, get_next_op_number(CG(active_op_array)));
    2232      178083 : }
    2233             : /* }}} */
    2234             : 
    2235      158895 : static inline zend_op *zend_delayed_emit_op(znode *result, zend_uchar opcode, znode *op1, znode *op2) /* {{{ */
    2236             : {
    2237             :         zend_op tmp_opline;
    2238      158895 :         init_op(&tmp_opline);
    2239      158895 :         tmp_opline.opcode = opcode;
    2240      158895 :         if (op1 == NULL) {
    2241           0 :                 SET_UNUSED(tmp_opline.op1);
    2242             :         } else {
    2243      158895 :                 SET_NODE(tmp_opline.op1, op1);
    2244             :         }
    2245      158895 :         if (op2 == NULL) {
    2246       17174 :                 SET_UNUSED(tmp_opline.op2);
    2247             :         } else {
    2248      141721 :                 SET_NODE(tmp_opline.op2, op2);
    2249             :         }
    2250      158895 :         if (result) {
    2251      158491 :                 zend_make_var_result(result, &tmp_opline);
    2252             :         }
    2253             : 
    2254      158895 :         zend_stack_push(&CG(delayed_oplines_stack), &tmp_opline);
    2255      158895 :         return zend_stack_top(&CG(delayed_oplines_stack));
    2256             : }
    2257             : /* }}} */
    2258             : 
    2259      291491 : static inline uint32_t zend_delayed_compile_begin(void) /* {{{ */
    2260             : {
    2261      291491 :         return zend_stack_count(&CG(delayed_oplines_stack));
    2262             : }
    2263             : /* }}} */
    2264             : 
    2265      291477 : static zend_op *zend_delayed_compile_end(uint32_t offset) /* {{{ */
    2266             : {
    2267      291477 :         zend_op *opline = NULL, *oplines = zend_stack_base(&CG(delayed_oplines_stack));
    2268      291477 :         uint32_t i, count = zend_stack_count(&CG(delayed_oplines_stack));
    2269             : 
    2270             :         ZEND_ASSERT(count >= offset);
    2271      450371 :         for (i = offset; i < count; ++i) {
    2272      158894 :                 opline = get_next_op(CG(active_op_array));
    2273      158894 :                 memcpy(opline, &oplines[i], sizeof(zend_op));
    2274      158894 :                 zend_check_live_ranges(opline);
    2275             :         }
    2276      291477 :         CG(delayed_oplines_stack).top = offset;
    2277      291477 :         return opline;
    2278             : }
    2279             : /* }}} */
    2280             : 
    2281         233 : static void zend_emit_return_type_check(
    2282             :                 znode *expr, zend_arg_info *return_info, zend_bool implicit) /* {{{ */
    2283             : {
    2284             :         /* `return ...;` is illegal in a void function (but `return;` isn't) */
    2285         233 :         if (return_info->type_hint == IS_VOID) {
    2286          10 :                 if (expr) {
    2287           4 :                         if (expr->op_type == IS_CONST && Z_TYPE(expr->u.constant) == IS_NULL) {
    2288           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    2289             :                                         "A void function must not return a value "
    2290             :                                         "(did you mean \"return;\" instead of \"return null;\"?)");
    2291             :                         } else {
    2292           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "A void function must not return a value");
    2293             :                         }
    2294             :                 }
    2295             :                 /* we don't need run-time check */
    2296           8 :                 return;
    2297             :         }
    2298             : 
    2299         223 :         if (return_info->type_hint != IS_UNDEF) {
    2300             :                 zend_op *opline;
    2301             : 
    2302         223 :                 if (!expr && !implicit) {
    2303           2 :                         if (return_info->allow_null) {
    2304           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    2305             :                                         "A function with return type must return a value "
    2306             :                                         "(did you mean \"return null;\" instead of \"return;\"?)");
    2307             :                         } else {
    2308           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    2309             :                                         "A function with return type must return a value");
    2310             :                         }
    2311             :                 }
    2312             : 
    2313         221 :                 if (expr && expr->op_type == IS_CONST) {
    2314          62 :                         if ((return_info->type_hint == Z_TYPE(expr->u.constant))
    2315          13 :                          ||((return_info->type_hint == _IS_BOOL)
    2316           0 :                           && (Z_TYPE(expr->u.constant) == IS_FALSE
    2317           0 :                            || Z_TYPE(expr->u.constant) == IS_TRUE))
    2318             :                          || (return_info->allow_null
    2319          13 :                           && Z_TYPE(expr->u.constant) == IS_NULL)) {
    2320             :                                 /* we don't need run-time check */
    2321           5 :                                 return;
    2322             :                         }
    2323             :                 }
    2324             : 
    2325         216 :                 opline = zend_emit_op(NULL, ZEND_VERIFY_RETURN_TYPE, expr, NULL);
    2326         216 :                 if (expr && expr->op_type == IS_CONST) {
    2327          13 :                         opline->result_type = expr->op_type = IS_TMP_VAR;
    2328          13 :                         opline->result.var = expr->u.op.var = get_temporary_variable(CG(active_op_array));
    2329             :                 }
    2330         216 :                 if (return_info->class_name) {
    2331          89 :                         opline->op2.num = CG(active_op_array)->cache_size;
    2332          89 :                         CG(active_op_array)->cache_size += sizeof(void*);
    2333             :                 } else {
    2334         127 :                         opline->op2.num = -1;
    2335             :                 }
    2336             :         }
    2337             : }
    2338             : /* }}} */
    2339             : 
    2340       73939 : void zend_emit_final_return(int return_one) /* {{{ */
    2341             : {
    2342             :         znode zn;
    2343             :         zend_op *ret;
    2344       73939 :         zend_bool returns_reference = (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;
    2345             : 
    2346      148028 :         if (CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE
    2347       74089 :                         && !(CG(active_op_array)->fn_flags & ZEND_ACC_GENERATOR)) {
    2348         139 :                 zend_emit_return_type_check(NULL, CG(active_op_array)->arg_info - 1, 1);
    2349             :         }
    2350             : 
    2351       73939 :         zn.op_type = IS_CONST;
    2352       73939 :         if (return_one) {
    2353       32916 :                 ZVAL_LONG(&zn.u.constant, 1);
    2354             :         } else {
    2355       41023 :                 ZVAL_NULL(&zn.u.constant);
    2356             :         }
    2357             : 
    2358       73939 :         ret = zend_emit_op(NULL, returns_reference ? ZEND_RETURN_BY_REF : ZEND_RETURN, &zn, NULL);
    2359       73939 :         ret->extended_value = -1;
    2360       73939 : }
    2361             : /* }}} */
    2362             : 
    2363      626682 : static inline zend_bool zend_is_variable(zend_ast *ast) /* {{{ */
    2364             : {
    2365     2476283 :         return ast->kind == ZEND_AST_VAR || ast->kind == ZEND_AST_DIM
    2366      713631 :                 || ast->kind == ZEND_AST_PROP || ast->kind == ZEND_AST_STATIC_PROP
    2367      617387 :                 || ast->kind == ZEND_AST_CALL || ast->kind == ZEND_AST_METHOD_CALL
    2368      518583 :                 || ast->kind == ZEND_AST_STATIC_CALL;
    2369             : }
    2370             : /* }}} */
    2371             : 
    2372      440431 : static inline zend_bool zend_is_call(zend_ast *ast) /* {{{ */
    2373             : {
    2374     1222601 :         return ast->kind == ZEND_AST_CALL
    2375      440431 :                 || ast->kind == ZEND_AST_METHOD_CALL
    2376      782170 :                 || ast->kind == ZEND_AST_STATIC_CALL;
    2377             : }
    2378             : /* }}} */
    2379             : 
    2380          41 : static inline zend_bool zend_is_unticked_stmt(zend_ast *ast) /* {{{ */
    2381             : {
    2382         197 :         return ast->kind == ZEND_AST_STMT_LIST || ast->kind == ZEND_AST_LABEL
    2383          63 :                 || ast->kind == ZEND_AST_PROP_DECL || ast->kind == ZEND_AST_CLASS_CONST_DECL
    2384          93 :                 || ast->kind == ZEND_AST_USE_TRAIT || ast->kind == ZEND_AST_METHOD;
    2385             : }
    2386             : /* }}} */
    2387             : 
    2388       10350 : static inline zend_bool zend_can_write_to_variable(zend_ast *ast) /* {{{ */
    2389             : {
    2390       23290 :         while (ast->kind == ZEND_AST_DIM || ast->kind == ZEND_AST_PROP) {
    2391        2590 :                 ast = ast->child[0];
    2392             :         }
    2393             : 
    2394       10350 :         return zend_is_variable(ast);
    2395             : }
    2396             : /* }}} */
    2397             : 
    2398        5792 : static inline zend_bool zend_is_const_default_class_ref(zend_ast *name_ast) /* {{{ */
    2399             : {
    2400        5792 :         if (name_ast->kind != ZEND_AST_ZVAL) {
    2401           0 :                 return 0;
    2402             :         }
    2403             : 
    2404        5792 :         return ZEND_FETCH_CLASS_DEFAULT == zend_get_class_fetch_type_ast(name_ast);
    2405             : }
    2406             : /* }}} */
    2407             : 
    2408      141039 : static inline void zend_handle_numeric_op(znode *node) /* {{{ */
    2409             : {
    2410      273051 :         if (node->op_type == IS_CONST && Z_TYPE(node->u.constant) == IS_STRING) {
    2411             :                 zend_ulong index;
    2412             : 
    2413      103230 :                 if (ZEND_HANDLE_NUMERIC(Z_STR(node->u.constant), index)) {
    2414          65 :                         zval_ptr_dtor(&node->u.constant);
    2415          65 :                         ZVAL_LONG(&node->u.constant, index);
    2416             :                 }
    2417             :         }
    2418      141039 : }
    2419             : /* }}} */
    2420             : 
    2421       11828 : static inline void zend_set_class_name_op1(zend_op *opline, znode *class_node) /* {{{ */
    2422             : {
    2423       11828 :         if (class_node->op_type == IS_CONST) {
    2424        6280 :                 opline->op1_type = IS_CONST;
    2425        6280 :                 opline->op1.constant = zend_add_class_name_literal(
    2426             :                         CG(active_op_array), Z_STR(class_node->u.constant));
    2427             :         } else {
    2428        5548 :                 SET_NODE(opline->op1, class_node);
    2429             :         }
    2430       11828 : }
    2431             : /* }}} */
    2432             : 
    2433        2504 : static zend_op *zend_compile_class_ref(znode *result, zend_ast *name_ast, int throw_exception) /* {{{ */
    2434             : {
    2435             :         zend_op *opline;
    2436             :         znode name_node;
    2437        2504 :         zend_compile_expr(&name_node, name_ast);
    2438             : 
    2439        2504 :         if (name_node.op_type == IS_CONST) {
    2440             :                 zend_string *name;
    2441             :                 uint32_t fetch_type;
    2442             : 
    2443        2504 :                 if (Z_TYPE(name_node.u.constant) != IS_STRING) {
    2444           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Illegal class name");
    2445             :                 }
    2446             : 
    2447        2504 :                 name = Z_STR(name_node.u.constant);
    2448        2504 :                 fetch_type = zend_get_class_fetch_type(name);
    2449             : 
    2450        2504 :                 opline = zend_emit_op(result, ZEND_FETCH_CLASS, NULL, NULL);
    2451        2504 :                 opline->extended_value = fetch_type | (throw_exception ? ZEND_FETCH_CLASS_EXCEPTION : 0);
    2452             : 
    2453        2504 :                 if (fetch_type == ZEND_FETCH_CLASS_DEFAULT) {
    2454        2504 :                         uint32_t type = name_ast->kind == ZEND_AST_ZVAL ? name_ast->attr : ZEND_NAME_FQ;
    2455        2504 :                         opline->op2_type = IS_CONST;
    2456        2504 :                         opline->op2.constant = zend_add_class_name_literal(CG(active_op_array),
    2457             :                                 zend_resolve_class_name(name, type));
    2458             :                 } else {
    2459           0 :                         zend_ensure_valid_class_fetch_type(fetch_type);
    2460             :                 }
    2461             : 
    2462             :                 zend_string_release(name);
    2463             :         } else {
    2464           0 :                 opline = zend_emit_op(result, ZEND_FETCH_CLASS, NULL, &name_node);
    2465           0 :                 opline->extended_value = ZEND_FETCH_CLASS_DEFAULT | (throw_exception ? ZEND_FETCH_CLASS_EXCEPTION : 0);
    2466             :         }
    2467             : 
    2468        2504 :         return opline;
    2469             : }
    2470             : /* }}} */
    2471             : 
    2472       28112 : static void zend_compile_class_ref_ex(znode *result, zend_ast *name_ast, uint32_t fetch_flags) /* {{{ */
    2473             : {
    2474             :         uint32_t fetch_type;
    2475             : 
    2476       28112 :         if (name_ast->kind != ZEND_AST_ZVAL) {
    2477             :                 znode name_node;
    2478             : 
    2479        1442 :                 zend_compile_expr(&name_node, name_ast);
    2480             : 
    2481        1442 :                 if (name_node.op_type == IS_CONST) {
    2482             :                         zend_string *name;
    2483             : 
    2484           2 :                         if (Z_TYPE(name_node.u.constant) != IS_STRING) {
    2485           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Illegal class name");
    2486             :                         }
    2487             : 
    2488           1 :                         name = Z_STR(name_node.u.constant);
    2489           1 :                         fetch_type = zend_get_class_fetch_type(name);
    2490             : 
    2491           1 :                         if (fetch_type == ZEND_FETCH_CLASS_DEFAULT) {
    2492           1 :                                 result->op_type = IS_CONST;
    2493           1 :                                 ZVAL_STR(&result->u.constant, zend_resolve_class_name(name, ZEND_NAME_FQ));
    2494             :                         } else {
    2495           0 :                                 zend_ensure_valid_class_fetch_type(fetch_type);
    2496           0 :                                 result->op_type = IS_UNUSED;
    2497           0 :                                 result->u.op.num = fetch_type | fetch_flags;
    2498             :                         }
    2499             : 
    2500             :                         zend_string_release(name);
    2501             :                 } else {
    2502        1440 :                         zend_op *opline = zend_emit_op(result, ZEND_FETCH_CLASS, NULL, &name_node);
    2503        1440 :                         opline->extended_value = ZEND_FETCH_CLASS_DEFAULT | fetch_flags;
    2504             :                 }
    2505        1441 :                 return;
    2506             :         }
    2507             : 
    2508             :         /* Fully qualified names are always default refs */
    2509       26670 :         if (name_ast->attr == ZEND_NAME_FQ) {
    2510         109 :                 result->op_type = IS_CONST;
    2511         109 :                 ZVAL_STR(&result->u.constant, zend_resolve_class_name_ast(name_ast));
    2512         109 :                 return;
    2513             :         }
    2514             : 
    2515       26561 :         fetch_type = zend_get_class_fetch_type(zend_ast_get_str(name_ast));
    2516       26561 :         if (ZEND_FETCH_CLASS_DEFAULT == fetch_type) {
    2517       20500 :                 result->op_type = IS_CONST;
    2518       20500 :                 ZVAL_STR(&result->u.constant, zend_resolve_class_name_ast(name_ast));
    2519             :         } else {
    2520        6061 :                 zend_ensure_valid_class_fetch_type(fetch_type);
    2521        6060 :                 result->op_type = IS_UNUSED;
    2522        6060 :                 result->u.op.num = fetch_type | fetch_flags;
    2523             :         }
    2524             : }
    2525             : /* }}} */
    2526             : 
    2527      694118 : static int zend_try_compile_cv(znode *result, zend_ast *ast) /* {{{ */
    2528             : {
    2529      694118 :         zend_ast *name_ast = ast->child[0];
    2530      694118 :         if (name_ast->kind == ZEND_AST_ZVAL) {
    2531      693909 :                 zend_string *name = zval_get_string(zend_ast_get_zval(name_ast));
    2532             : 
    2533      693909 :                 if (zend_is_auto_global(name)) {
    2534             :                         zend_string_release(name);
    2535       17284 :                         return FAILURE;
    2536             :                 }
    2537             : 
    2538      676625 :                 result->op_type = IS_CV;
    2539      676625 :                 result->u.op.var = lookup_cv(CG(active_op_array), name);
    2540             : 
    2541             :                 /* lookup_cv may be using another zend_string instance  */
    2542      676625 :                 name = CG(active_op_array)->vars[EX_VAR_TO_NUM(result->u.op.var)];
    2543             : 
    2544      676625 :                 return SUCCESS;
    2545             :         }
    2546             : 
    2547         209 :         return FAILURE;
    2548             : }
    2549             : /* }}} */
    2550             : 
    2551       18991 : static zend_op *zend_compile_simple_var_no_cv(znode *result, zend_ast *ast, uint32_t type, int delayed) /* {{{ */
    2552             : {
    2553       18991 :         zend_ast *name_ast = ast->child[0];
    2554             :         znode name_node;
    2555             :         zend_op *opline;
    2556             : 
    2557       18991 :         zend_compile_expr(&name_node, name_ast);
    2558       18991 :         if (name_node.op_type == IS_CONST) {
    2559       18788 :                 convert_to_string(&name_node.u.constant);
    2560             :         }
    2561             : 
    2562       18991 :         if (delayed) {
    2563       16940 :                 opline = zend_delayed_emit_op(result, ZEND_FETCH_R, &name_node, NULL);
    2564             :         } else {
    2565        2051 :                 opline = zend_emit_op(result, ZEND_FETCH_R, &name_node, NULL);
    2566             :         }
    2567             : 
    2568       55063 :         if (name_node.op_type == IS_CONST && 
    2569       18788 :             zend_is_auto_global(Z_STR(name_node.u.constant))) {
    2570             : 
    2571       17284 :                 opline->extended_value = ZEND_FETCH_GLOBAL;
    2572             :         } else {
    2573        1707 :                 opline->extended_value = ZEND_FETCH_LOCAL;
    2574             :         }
    2575             : 
    2576       18991 :         return opline;
    2577             : }
    2578             : /* }}} */
    2579             : 
    2580      907903 : static zend_bool is_this_fetch(zend_ast *ast) /* {{{ */
    2581             : {
    2582      907903 :         if (ast->kind == ZEND_AST_VAR && ast->child[0]->kind == ZEND_AST_ZVAL) {
    2583     1785974 :                 zval *name = zend_ast_get_zval(ast->child[0]);
    2584      892987 :                 return Z_TYPE_P(name) == IS_STRING && zend_string_equals_literal(Z_STR_P(name), "this");
    2585             :         }
    2586             : 
    2587       14916 :         return 0;
    2588             : }
    2589             : /* }}} */
    2590             : 
    2591      671680 : static void zend_compile_simple_var(znode *result, zend_ast *ast, uint32_t type, int delayed) /* {{{ */
    2592             : {
    2593             :         zend_op *opline;
    2594             : 
    2595      671680 :         if (is_this_fetch(ast)) {
    2596         367 :                 opline = zend_emit_op(result, ZEND_FETCH_THIS, NULL, NULL);
    2597         367 :                 zend_adjust_for_fetch_type(opline, type);
    2598      671313 :         } else if (zend_try_compile_cv(result, ast) == FAILURE) {
    2599       17460 :                 zend_op *opline = zend_compile_simple_var_no_cv(result, ast, type, delayed);
    2600       17460 :                 zend_adjust_for_fetch_type(opline, type);
    2601             :         }
    2602      671680 : }
    2603             : /* }}} */
    2604             : 
    2605      138282 : static void zend_separate_if_call_and_write(znode *node, zend_ast *ast, uint32_t type) /* {{{ */
    2606             : {
    2607      138282 :         if (type != BP_VAR_R && type != BP_VAR_IS && zend_is_call(ast)) {
    2608          57 :                 if (node->op_type == IS_VAR) {
    2609          56 :                         zend_op *opline = zend_emit_op(NULL, ZEND_SEPARATE, node, NULL);
    2610          56 :                         opline->result_type = IS_VAR;
    2611          56 :                         opline->result.var = opline->op1.var;
    2612             :                 } else {
    2613           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use result of built-in function in write context");
    2614             :                 }
    2615             :         }
    2616      138281 : }
    2617             : /* }}} */
    2618             : 
    2619             : void zend_delayed_compile_var(znode *result, zend_ast *ast, uint32_t type);
    2620             : void zend_compile_assign(znode *result, zend_ast *ast);
    2621             : static void zend_compile_list_assign(znode *result, zend_ast *ast, znode *expr_node, zend_bool old_style);
    2622             : 
    2623        5746 : static inline void zend_emit_assign_znode(zend_ast *var_ast, znode *value_node) /* {{{ */
    2624             : {
    2625             :         znode dummy_node;
    2626        5746 :         if (var_ast->kind == ZEND_AST_ARRAY) {
    2627          43 :                 zend_compile_list_assign(&dummy_node, var_ast, value_node, var_ast->attr);
    2628             :         } else {
    2629        5703 :                 zend_ast *assign_ast = zend_ast_create(ZEND_AST_ASSIGN, var_ast,
    2630        5703 :                         zend_ast_create_znode(value_node));
    2631        5703 :                 zend_compile_assign(&dummy_node, assign_ast);
    2632             :         }
    2633        5742 :         zend_do_free(&dummy_node);
    2634        5742 : }
    2635             : /* }}} */
    2636             : 
    2637      130736 : static zend_op *zend_delayed_compile_dim(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    2638             : {
    2639      130736 :         zend_ast *var_ast = ast->child[0];
    2640      130736 :         zend_ast *dim_ast = ast->child[1];
    2641             : 
    2642             :         znode var_node, dim_node;
    2643             : 
    2644      130736 :         zend_delayed_compile_var(&var_node, var_ast, type);
    2645      130734 :         zend_separate_if_call_and_write(&var_node, var_ast, type);
    2646             : 
    2647      130733 :         if (dim_ast == NULL) {
    2648         622 :                 if (type == BP_VAR_R || type == BP_VAR_IS) {
    2649           7 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use [] for reading");
    2650             :                 }
    2651         615 :                 if (type == BP_VAR_UNSET) {
    2652           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use [] for unsetting");
    2653             :                 }
    2654         614 :                 dim_node.op_type = IS_UNUSED;
    2655             :         } else {
    2656      130111 :                 zend_compile_expr(&dim_node, dim_ast);
    2657      130111 :                 zend_handle_numeric_op(&dim_node);
    2658             :         }
    2659             : 
    2660      130725 :         return zend_delayed_emit_op(result, ZEND_FETCH_DIM_R, &var_node, &dim_node);
    2661             : }
    2662             : /* }}} */
    2663             : 
    2664      116577 : static inline zend_op *zend_compile_dim_common(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    2665             : {
    2666      116577 :         uint32_t offset = zend_delayed_compile_begin();
    2667      116577 :         zend_delayed_compile_dim(result, ast, type);
    2668      116569 :         return zend_delayed_compile_end(offset);
    2669             : }
    2670             : /* }}} */
    2671             : 
    2672      107833 : void zend_compile_dim(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    2673             : {
    2674      107833 :         zend_op *opline = zend_compile_dim_common(result, ast, type);
    2675      107827 :         zend_adjust_for_fetch_type(opline, type);
    2676      107827 : }
    2677             : /* }}} */
    2678             : 
    2679       10996 : static zend_op *zend_delayed_compile_prop(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    2680             : {
    2681       10996 :         zend_ast *obj_ast = ast->child[0];
    2682       10996 :         zend_ast *prop_ast = ast->child[1];
    2683             : 
    2684             :         znode obj_node, prop_node;
    2685             :         zend_op *opline;
    2686             : 
    2687       10996 :         if (is_this_fetch(obj_ast)) {
    2688        3560 :                 obj_node.op_type = IS_UNUSED;
    2689             :         } else {
    2690        7436 :                 zend_delayed_compile_var(&obj_node, obj_ast, type);
    2691        7436 :                 zend_separate_if_call_and_write(&obj_node, obj_ast, type);
    2692             :         }
    2693       10996 :         zend_compile_expr(&prop_node, prop_ast);
    2694             : 
    2695       10996 :         opline = zend_delayed_emit_op(result, ZEND_FETCH_OBJ_R, &obj_node, &prop_node);
    2696       10996 :         if (opline->op2_type == IS_CONST) {
    2697       21656 :                 convert_to_string(CT_CONSTANT(opline->op2));
    2698       10828 :                 zend_alloc_polymorphic_cache_slot(opline->op2.constant);
    2699             :         }
    2700             : 
    2701       10996 :         return opline;
    2702             : }
    2703             : /* }}} */
    2704             : 
    2705        7470 : static zend_op *zend_compile_prop_common(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    2706             : {
    2707        7470 :         uint32_t offset = zend_delayed_compile_begin();
    2708        7470 :         zend_delayed_compile_prop(result, ast, type);
    2709        7470 :         return zend_delayed_compile_end(offset);
    2710             : }
    2711             : /* }}} */
    2712             : 
    2713        6538 : void zend_compile_prop(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    2714             : {
    2715        6538 :         zend_op *opline = zend_compile_prop_common(result, ast, type);
    2716        6538 :         zend_adjust_for_fetch_type(opline, type);
    2717        6538 : }
    2718             : /* }}} */
    2719             : 
    2720         801 : zend_op *zend_compile_static_prop_common(znode *result, zend_ast *ast, uint32_t type, int delayed) /* {{{ */
    2721             : {
    2722         801 :         zend_ast *class_ast = ast->child[0];
    2723         801 :         zend_ast *prop_ast = ast->child[1];
    2724             : 
    2725             :         znode class_node, prop_node;
    2726             :         zend_op *opline;
    2727             : 
    2728         801 :         zend_compile_class_ref_ex(&class_node, class_ast, ZEND_FETCH_CLASS_EXCEPTION);
    2729             : 
    2730         800 :         zend_compile_expr(&prop_node, prop_ast);
    2731             : 
    2732         800 :         if (delayed) {
    2733         234 :                 opline = zend_delayed_emit_op(result, ZEND_FETCH_STATIC_PROP_R, &prop_node, NULL);
    2734             :         } else {
    2735         566 :                 opline = zend_emit_op(result, ZEND_FETCH_STATIC_PROP_R, &prop_node, NULL);
    2736             :         }
    2737         800 :         if (opline->op1_type == IS_CONST) {
    2738        1582 :                 convert_to_string(CT_CONSTANT(opline->op1));
    2739         791 :                 zend_alloc_polymorphic_cache_slot(opline->op1.constant);
    2740             :         }
    2741         800 :         if (class_node.op_type == IS_CONST) {
    2742         323 :                 opline->op2_type = IS_CONST;
    2743         323 :                 opline->op2.constant = zend_add_class_name_literal(
    2744             :                         CG(active_op_array), Z_STR(class_node.u.constant));
    2745             :         } else {
    2746         477 :                 SET_NODE(opline->op2, &class_node);
    2747             :         }
    2748             : 
    2749         800 :         return opline;
    2750             : }
    2751             : /* }}} */
    2752             : 
    2753         663 : void zend_compile_static_prop(znode *result, zend_ast *ast, uint32_t type, int delayed) /* {{{ */
    2754             : {
    2755         663 :         zend_op *opline = zend_compile_static_prop_common(result, ast, type, delayed);
    2756         662 :         zend_adjust_for_fetch_type(opline, type);
    2757         662 : }
    2758             : /* }}} */
    2759             : 
    2760         513 : static void zend_verify_list_assign_target(zend_ast *var_ast, zend_bool old_style) /* {{{ */ {
    2761         513 :         if (var_ast->kind == ZEND_AST_ARRAY) {
    2762          33 :                 if (var_ast->attr == ZEND_ARRAY_SYNTAX_LONG) {
    2763           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot assign to array(), use [] instead");
    2764             :                 }
    2765          32 :                 if (old_style != var_ast->attr) {
    2766           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot mix [] and list()");
    2767             :                 }
    2768         480 :         } else if (!zend_can_write_to_variable(var_ast)) {
    2769           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Assignments can only happen to writable values");
    2770             :         }
    2771         510 : }
    2772             : /* }}} */
    2773             : 
    2774         206 : static void zend_compile_unkeyed_list_assign(zend_ast_list *list, znode *expr_node, zend_bool old_style) /* {{{ */
    2775             : {
    2776             :         uint32_t i;
    2777         206 :         zend_bool has_elems = 0;
    2778             : 
    2779         672 :         for (i = 0; i < list->children; ++i) {
    2780         472 :                 zend_ast *elem_ast = list->child[i];
    2781             :                 zend_ast *var_ast;
    2782             :                 znode fetch_result, dim_node;
    2783             : 
    2784         472 :                 if (elem_ast == NULL) {
    2785          31 :                         continue;
    2786             :                 }
    2787         441 :                 if (elem_ast->attr) {
    2788           1 :                         zend_error(E_COMPILE_ERROR, "[] and list() assignments cannot be by reference");
    2789             :                 }
    2790             : 
    2791         440 :                 var_ast = elem_ast->child[0];
    2792         440 :                 has_elems = 1;
    2793             : 
    2794         440 :                 dim_node.op_type = IS_CONST;
    2795         440 :                 ZVAL_LONG(&dim_node.u.constant, i);
    2796             : 
    2797         440 :                 if (expr_node->op_type == IS_CONST) {
    2798          38 :                         Z_TRY_ADDREF(expr_node->u.constant);
    2799             :                 }
    2800             : 
    2801         440 :                 if (elem_ast->child[1] != NULL) {
    2802           1 :                         zend_error(E_COMPILE_ERROR, "Cannot mix keyed and unkeyed array entries in assignments");
    2803             :                 }
    2804             : 
    2805         439 :                 zend_verify_list_assign_target(var_ast, old_style);
    2806             : 
    2807         436 :                 zend_emit_op(&fetch_result, ZEND_FETCH_LIST, expr_node, &dim_node);
    2808         436 :                 zend_emit_assign_znode(var_ast, &fetch_result);
    2809             :         }
    2810             : 
    2811         200 :         if (has_elems == 0) {
    2812           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use empty list");
    2813             :         }
    2814             : 
    2815         198 : }
    2816             : /* }}} */
    2817             : 
    2818          36 : static void zend_compile_keyed_list_assign(zend_ast_list *list, znode *expr_node, zend_bool old_style) /* {{{ */
    2819             : {
    2820             :         uint32_t i;
    2821             : 
    2822         110 :         for (i = 0; i < list->children; ++i) {
    2823          75 :                 zend_ast *pair_ast = list->child[i];
    2824          75 :                 zend_ast *var_ast = pair_ast->child[0];
    2825          75 :                 zend_ast *key_ast = pair_ast->child[1];
    2826             :                 znode fetch_result, dim_node;
    2827             : 
    2828          75 :                 if (pair_ast->attr) {
    2829           0 :                         zend_error(E_COMPILE_ERROR, "[] and list() assignments cannot be by reference");
    2830             :                 }
    2831             : 
    2832          75 :                 if (key_ast == NULL) {
    2833           1 :                         zend_error(E_COMPILE_ERROR, "Cannot mix keyed and unkeyed array entries in assignments");
    2834             :                 }
    2835             : 
    2836          74 :                 zend_compile_expr(&dim_node, key_ast);
    2837             : 
    2838          74 :                 if (expr_node->op_type == IS_CONST) {
    2839          14 :                         Z_TRY_ADDREF(expr_node->u.constant);
    2840             :                 }
    2841             : 
    2842          74 :                 if (var_ast == NULL) {
    2843           0 :                         zend_error(E_COMPILE_ERROR, "Cannot use empty array entries in keyed array");
    2844             :                 }
    2845             : 
    2846          74 :                 zend_verify_list_assign_target(var_ast, old_style);
    2847             : 
    2848          74 :                 zend_emit_op(&fetch_result, ZEND_FETCH_LIST, expr_node, &dim_node);
    2849          74 :                 zend_emit_assign_znode(var_ast, &fetch_result);
    2850             :         }
    2851          35 : }
    2852             : /* }}} */
    2853             : 
    2854         242 : static void zend_compile_list_assign(znode *result, zend_ast *ast, znode *expr_node, zend_bool old_style) /* {{{ */
    2855             : {
    2856         242 :         zend_ast_list *list = zend_ast_get_list(ast);
    2857             : 
    2858         277 :         if (list->children > 0 && list->child[0] != NULL && list->child[0]->child[1] != NULL /* has key */) {
    2859          36 :                 zend_compile_keyed_list_assign(list, expr_node, old_style);
    2860             :         } else {
    2861         206 :                 zend_compile_unkeyed_list_assign(list, expr_node, old_style);
    2862             :         }
    2863             : 
    2864         233 :         *result = *expr_node;
    2865         233 : }
    2866             : /* }}} */
    2867             : 
    2868      176198 : static void zend_ensure_writable_variable(const zend_ast *ast) /* {{{ */
    2869             : {
    2870      176198 :         if (ast->kind == ZEND_AST_CALL) {
    2871           3 :                 zend_error_noreturn(E_COMPILE_ERROR, "Can't use function return value in write context");
    2872             :         }
    2873      176195 :         if (ast->kind == ZEND_AST_METHOD_CALL || ast->kind == ZEND_AST_STATIC_CALL) {
    2874           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Can't use method return value in write context");
    2875             :         }
    2876      176194 : }
    2877             : /* }}} */
    2878             : 
    2879             : /* Detects $a... = $a pattern */
    2880        9376 : zend_bool zend_is_assign_to_self(zend_ast *var_ast, zend_ast *expr_ast) /* {{{ */
    2881             : {
    2882        9376 :         if (expr_ast->kind != ZEND_AST_VAR || expr_ast->child[0]->kind != ZEND_AST_ZVAL) {
    2883        7353 :                 return 0;
    2884             :         }
    2885             : 
    2886        6157 :         while (zend_is_variable(var_ast) && var_ast->kind != ZEND_AST_VAR) {
    2887        2111 :                 var_ast = var_ast->child[0];
    2888             :         }
    2889             : 
    2890        2023 :         if (var_ast->kind != ZEND_AST_VAR || var_ast->child[0]->kind != ZEND_AST_ZVAL) {
    2891           2 :                 return 0;
    2892             :         }
    2893             : 
    2894             :         {
    2895        4042 :                 zend_string *name1 = zval_get_string(zend_ast_get_zval(var_ast->child[0]));
    2896        4042 :                 zend_string *name2 = zval_get_string(zend_ast_get_zval(expr_ast->child[0]));
    2897        2021 :                 zend_bool result = zend_string_equals(name1, name2);
    2898             :                 zend_string_release(name1);
    2899             :                 zend_string_release(name2);
    2900        2021 :                 return result;
    2901             :         }
    2902             : }
    2903             : /* }}} */
    2904             : 
    2905             : /* Detects if list($a, $b, $c) contains variable with given name */
    2906          59 : zend_bool zend_list_has_assign_to(zend_ast *list_ast, zend_string *name) /* {{{ */
    2907             : {
    2908          59 :         zend_ast_list *list = zend_ast_get_list(list_ast);
    2909             :         uint32_t i;
    2910         181 :         for (i = 0; i < list->children; i++) {
    2911         133 :                 zend_ast *elem_ast = list->child[i];
    2912             :                 zend_ast *var_ast;
    2913             : 
    2914         133 :                 if (!elem_ast) {
    2915           5 :                         continue;
    2916             :                 }
    2917         128 :                 var_ast = elem_ast->child[0];
    2918             : 
    2919             :                 /* Recursively check nested list()s */
    2920         128 :                 if (var_ast->kind == ZEND_AST_ARRAY && zend_list_has_assign_to(var_ast, name)) {
    2921           4 :                         return 1;
    2922             :                 }
    2923             : 
    2924         124 :                 if (var_ast->kind == ZEND_AST_VAR && var_ast->child[0]->kind == ZEND_AST_ZVAL) {
    2925         226 :                         zend_string *var_name = zval_get_string(zend_ast_get_zval(var_ast->child[0]));
    2926         113 :                         zend_bool result = zend_string_equals(var_name, name);
    2927             :                         zend_string_release(var_name);
    2928         113 :                         if (result) {
    2929           7 :                                 return 1;
    2930             :                         }
    2931             :                 }
    2932             :         }
    2933             : 
    2934          48 :         return 0;
    2935             : }
    2936             : /* }}} */
    2937             : 
    2938             : /* Detects patterns like list($a, $b, $c) = $a */
    2939         199 : zend_bool zend_list_has_assign_to_self(zend_ast *list_ast, zend_ast *expr_ast) /* {{{ */
    2940             : {
    2941             :         /* Only check simple variables on the RHS, as only CVs cause issues with this. */
    2942         199 :         if (expr_ast->kind == ZEND_AST_VAR && expr_ast->child[0]->kind == ZEND_AST_ZVAL) {
    2943          88 :                 zend_string *name = zval_get_string(zend_ast_get_zval(expr_ast->child[0]));
    2944          44 :                 zend_bool result = zend_list_has_assign_to(list_ast, name);
    2945             :                 zend_string_release(name);
    2946          44 :                 return result;
    2947             :         }
    2948         155 :         return 0;
    2949             : }
    2950             : /* }}} */
    2951             : 
    2952      163011 : void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
    2953             : {
    2954      163011 :         zend_ast *var_ast = ast->child[0];
    2955      163011 :         zend_ast *expr_ast = ast->child[1];
    2956             : 
    2957             :         znode var_node, expr_node;
    2958             :         zend_op *opline;
    2959             :         uint32_t offset;
    2960             : 
    2961      163011 :         if (is_this_fetch(var_ast)) {
    2962           4 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
    2963             :         }
    2964             : 
    2965      163007 :         zend_ensure_writable_variable(var_ast);
    2966             : 
    2967      163005 :         switch (var_ast->kind) {
    2968             :                 case ZEND_AST_VAR:
    2969             :                 case ZEND_AST_STATIC_PROP:
    2970      151306 :                         offset = zend_delayed_compile_begin();
    2971      151306 :                         zend_delayed_compile_var(&var_node, var_ast, BP_VAR_W);
    2972      151306 :                         zend_compile_expr(&expr_node, expr_ast);
    2973      151302 :                         zend_delayed_compile_end(offset);
    2974      151302 :                         zend_emit_op(result, ZEND_ASSIGN, &var_node, &expr_node);
    2975      151302 :                         return;
    2976             :                 case ZEND_AST_DIM:
    2977        9378 :                         offset = zend_delayed_compile_begin();
    2978        9378 :                         zend_delayed_compile_dim(result, var_ast, BP_VAR_W);
    2979             : 
    2980        9410 :                         if (zend_is_assign_to_self(var_ast, expr_ast)
    2981        9395 :                          && !is_this_fetch(expr_ast)) {
    2982             :                                 /* $a[0] = $a should evaluate the right $a first */
    2983          15 :                                 zend_compile_simple_var_no_cv(&expr_node, expr_ast, BP_VAR_R, 0);
    2984             :                         } else {
    2985        9361 :                                 zend_compile_expr(&expr_node, expr_ast);
    2986             :                         }
    2987             : 
    2988        9376 :                         opline = zend_delayed_compile_end(offset);
    2989        9376 :                         opline->opcode = ZEND_ASSIGN_DIM;
    2990             : 
    2991        9376 :                         opline = zend_emit_op_data(&expr_node);
    2992        9376 :                         return;
    2993             :                 case ZEND_AST_PROP:
    2994        2122 :                         offset = zend_delayed_compile_begin();
    2995        2122 :                         zend_delayed_compile_prop(result, var_ast, BP_VAR_W);
    2996        2122 :                         zend_compile_expr(&expr_node, expr_ast);
    2997             : 
    2998        2122 :                         opline = zend_delayed_compile_end(offset);
    2999        2122 :                         opline->opcode = ZEND_ASSIGN_OBJ;
    3000             : 
    3001        2122 :                         zend_emit_op_data(&expr_node);
    3002        2122 :                         return;
    3003             :                 case ZEND_AST_ARRAY:
    3004         199 :                         if (zend_list_has_assign_to_self(var_ast, expr_ast)) {
    3005             :                                 /* list($a, $b) = $a should evaluate the right $a first */
    3006           7 :                                 zend_compile_simple_var_no_cv(&expr_node, expr_ast, BP_VAR_R, 0);
    3007             :                         } else {
    3008         192 :                                 zend_compile_expr(&expr_node, expr_ast);
    3009             :                         }
    3010             : 
    3011         199 :                         zend_compile_list_assign(result, var_ast, &expr_node, var_ast->attr);
    3012         192 :                         return;
    3013             :                 EMPTY_SWITCH_DEFAULT_CASE();
    3014             :         }
    3015             : }
    3016             : /* }}} */
    3017             : 
    3018         491 : void zend_compile_assign_ref(znode *result, zend_ast *ast) /* {{{ */
    3019             : {
    3020         491 :         zend_ast *target_ast = ast->child[0];
    3021         491 :         zend_ast *source_ast = ast->child[1];
    3022             : 
    3023             :         znode target_node, source_node;
    3024             :         zend_op *opline;
    3025             :         uint32_t offset;
    3026             : 
    3027         491 :         if (is_this_fetch(target_ast)) {
    3028           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
    3029             :         }
    3030         490 :         zend_ensure_writable_variable(target_ast);
    3031             : 
    3032         490 :         offset = zend_delayed_compile_begin();
    3033         490 :         zend_delayed_compile_var(&target_node, target_ast, BP_VAR_W);
    3034         490 :         zend_compile_var(&source_node, source_ast, BP_VAR_W);
    3035             : 
    3036         984 :         if ((target_ast->kind != ZEND_AST_VAR
    3037         769 :           || target_ast->child[0]->kind != ZEND_AST_ZVAL)
    3038         215 :          && source_node.op_type != IS_CV) {
    3039             :                 /* Both LHS and RHS expressions may modify the same data structure,
    3040             :                  * and the modification during RHS evaluation may dangle the pointer
    3041             :                  * to the result of the LHS evaluation.
    3042             :                  * Use MAKE_REF instruction to replace direct pointer with REFERENCE.
    3043             :                  * See: Bug #71539
    3044             :                  */
    3045          92 :                 zend_emit_op(&source_node, ZEND_MAKE_REF, &source_node, NULL);
    3046             :         }
    3047             : 
    3048         490 :         zend_delayed_compile_end(offset);
    3049             : 
    3050         490 :         if (source_node.op_type != IS_VAR && zend_is_call(source_ast)) {
    3051           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use result of built-in function in write context");
    3052             :         }
    3053             : 
    3054         489 :         opline = zend_emit_op(result, ZEND_ASSIGN_REF, &target_node, &source_node);
    3055             : 
    3056         489 :         if (zend_is_call(source_ast)) {
    3057          47 :                 opline->extended_value = ZEND_RETURNS_FUNCTION;
    3058             :         }
    3059         489 : }
    3060             : /* }}} */
    3061             : 
    3062           3 : static inline void zend_emit_assign_ref_znode(zend_ast *var_ast, znode *value_node) /* {{{ */
    3063             : {
    3064           3 :         zend_ast *assign_ast = zend_ast_create(ZEND_AST_ASSIGN_REF, var_ast,
    3065           3 :                 zend_ast_create_znode(value_node));
    3066           3 :         zend_compile_assign_ref(NULL, assign_ast);
    3067           3 : }
    3068             : /* }}} */
    3069             : 
    3070        4148 : void zend_compile_compound_assign(znode *result, zend_ast *ast) /* {{{ */
    3071             : {
    3072        4148 :         zend_ast *var_ast = ast->child[0];
    3073        4148 :         zend_ast *expr_ast = ast->child[1];
    3074        4148 :         uint32_t opcode = ast->attr;
    3075             : 
    3076             :         znode var_node, expr_node;
    3077             :         zend_op *opline;
    3078             :         uint32_t offset;
    3079             : 
    3080        4148 :         zend_ensure_writable_variable(var_ast);
    3081             : 
    3082        4148 :         switch (var_ast->kind) {
    3083             :                 case ZEND_AST_VAR:
    3084             :                 case ZEND_AST_STATIC_PROP:
    3085        4038 :                         offset = zend_delayed_compile_begin();
    3086        4038 :                         zend_delayed_compile_var(&var_node, var_ast, BP_VAR_RW);
    3087        4038 :                         zend_compile_expr(&expr_node, expr_ast);
    3088        4038 :                         zend_delayed_compile_end(offset);
    3089        4038 :                         zend_emit_op(result, opcode, &var_node, &expr_node);
    3090        4038 :                         return;
    3091             :                 case ZEND_AST_DIM:
    3092          55 :                         offset = zend_delayed_compile_begin();
    3093          55 :                         zend_delayed_compile_dim(result, var_ast, BP_VAR_RW);
    3094          55 :                         zend_compile_expr(&expr_node, expr_ast);
    3095             : 
    3096          55 :                         opline = zend_delayed_compile_end(offset);
    3097          55 :                         opline->opcode = opcode;
    3098          55 :                         opline->extended_value = ZEND_ASSIGN_DIM;
    3099             : 
    3100          55 :                         opline = zend_emit_op_data(&expr_node);
    3101          55 :                         return;
    3102             :                 case ZEND_AST_PROP:
    3103          55 :                         offset = zend_delayed_compile_begin();
    3104          55 :                         zend_delayed_compile_prop(result, var_ast, BP_VAR_RW);
    3105          55 :                         zend_compile_expr(&expr_node, expr_ast);
    3106             : 
    3107          55 :                         opline = zend_delayed_compile_end(offset);
    3108          55 :                         opline->opcode = opcode;
    3109          55 :                         opline->extended_value = ZEND_ASSIGN_OBJ;
    3110             : 
    3111          55 :                         zend_emit_op_data(&expr_node);
    3112          55 :                         return;
    3113             :                 EMPTY_SWITCH_DEFAULT_CASE()
    3114             :         }
    3115             : }
    3116             : /* }}} */
    3117             : 
    3118      345113 : uint32_t zend_compile_args(zend_ast *ast, zend_function *fbc) /* {{{ */
    3119             : {
    3120      345113 :         zend_ast_list *args = zend_ast_get_list(ast);
    3121             :         uint32_t i;
    3122      345113 :         zend_bool uses_arg_unpack = 0;
    3123      345113 :         uint32_t arg_count = 0; /* number of arguments not including unpacks */
    3124             : 
    3125      931472 :         for (i = 0; i < args->children; ++i) {
    3126      586375 :                 zend_ast *arg = args->child[i];
    3127      586375 :                 uint32_t arg_num = i + 1;
    3128             : 
    3129             :                 znode arg_node;
    3130             :                 zend_op *opline;
    3131             :                 zend_uchar opcode;
    3132             : 
    3133      586375 :                 if (arg->kind == ZEND_AST_UNPACK) {
    3134          72 :                         uses_arg_unpack = 1;
    3135          72 :                         fbc = NULL;
    3136             : 
    3137          72 :                         zend_compile_expr(&arg_node, arg->child[0]);
    3138          72 :                         opline = zend_emit_op(NULL, ZEND_SEND_UNPACK, &arg_node, NULL);
    3139          72 :                         opline->op2.num = arg_count;
    3140          72 :                         opline->result.var = (uint32_t)(zend_intptr_t)ZEND_CALL_ARG(NULL, arg_count);
    3141          72 :                         continue;
    3142             :                 }
    3143             : 
    3144      586303 :                 if (uses_arg_unpack) {
    3145           1 :                         zend_error_noreturn(E_COMPILE_ERROR,
    3146             :                                 "Cannot use positional argument after argument unpacking");
    3147             :                 }
    3148             : 
    3149      586302 :                 arg_count++;
    3150      586302 :                 if (zend_is_variable(arg)) {
    3151      330729 :                         if (zend_is_call(arg)) {
    3152       50803 :                                 zend_compile_var(&arg_node, arg, BP_VAR_R);
    3153       50800 :                                 if (arg_node.op_type & (IS_CONST|IS_TMP_VAR)) {
    3154             :                                         /* Function call was converted into builtin instruction */
    3155        1752 :                                         opcode = ZEND_SEND_VAL;
    3156             :                                 } else {
    3157       49048 :                                         if (fbc) {
    3158       48067 :                                                 if (ARG_MUST_BE_SENT_BY_REF(fbc, arg_num)) {
    3159          20 :                                                         opcode = ZEND_SEND_VAR_NO_REF;
    3160       48047 :                                                 } else if (ARG_MAY_BE_SENT_BY_REF(fbc, arg_num)) {
    3161           2 :                                                         opcode = ZEND_SEND_VAL;
    3162             :                                                 } else {
    3163       48045 :                                                         opcode = ZEND_SEND_VAR;
    3164             :                                                 }
    3165             :                                         } else {
    3166         981 :                                                 opcode = ZEND_SEND_VAR_NO_REF_EX;
    3167             :                                         }
    3168             :                                 }
    3169      279926 :                         } else if (fbc) {
    3170      237564 :                                 if (ARG_SHOULD_BE_SENT_BY_REF(fbc, arg_num)) {
    3171       74754 :                                         zend_compile_var(&arg_node, arg, BP_VAR_W);
    3172       74754 :                                         opcode = ZEND_SEND_REF;
    3173             :                                 } else {
    3174      162810 :                                         zend_compile_var(&arg_node, arg, BP_VAR_R);
    3175      162809 :                                         opcode = ZEND_SEND_VAR;
    3176             :                                 }
    3177             :                         } else {
    3178       42362 :                                 zend_compile_var(&arg_node, arg,
    3179       42362 :                                         BP_VAR_FUNC_ARG | (arg_num << BP_VAR_SHIFT));
    3180       42362 :                                 opcode = ZEND_SEND_VAR_EX;
    3181             :                         }
    3182             :                 } else {
    3183      255573 :                         zend_compile_expr(&arg_node, arg);
    3184             :                         ZEND_ASSERT(arg_node.op_type != IS_CV);
    3185      255569 :                         if (arg_node.op_type == IS_VAR) {
    3186             :                                 /* pass ++$a or something similar */
    3187        2495 :                                 if (fbc) {
    3188        1674 :                                         if (ARG_MUST_BE_SENT_BY_REF(fbc, arg_num)) {
    3189           4 :                                                 opcode = ZEND_SEND_VAR_NO_REF;
    3190        1670 :                                         } else if (ARG_MAY_BE_SENT_BY_REF(fbc, arg_num)) {
    3191           0 :                                                 opcode = ZEND_SEND_VAL;
    3192             :                                         } else {
    3193        1670 :                                                 opcode = ZEND_SEND_VAR;
    3194             :                                         }
    3195             :                                 } else {
    3196         821 :                                         opcode = ZEND_SEND_VAR_NO_REF_EX;
    3197             :                                 }
    3198             :                         } else {
    3199      253074 :                                 if (fbc) {
    3200      212751 :                                         opcode = ZEND_SEND_VAL;
    3201      212751 :                                         if (ARG_MUST_BE_SENT_BY_REF(fbc, arg_num)) {
    3202           7 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Only variables can be passed by reference");
    3203             :                                         }
    3204             :                                 } else {
    3205       40323 :                                         opcode = ZEND_SEND_VAL_EX;
    3206             :                                 }
    3207             :                         }
    3208             :                 }
    3209             : 
    3210      586287 :                 opline = zend_emit_op(NULL, opcode, &arg_node, NULL);
    3211      586287 :                 opline->op2.opline_num = arg_num;
    3212      586287 :                 opline->result.var = (uint32_t)(zend_intptr_t)ZEND_CALL_ARG(NULL, arg_num);
    3213             :         }
    3214             : 
    3215      345097 :         return arg_count;
    3216             : }
    3217             : /* }}} */
    3218             : 
    3219      345097 : ZEND_API zend_uchar zend_get_call_op(const zend_op *init_op, zend_function *fbc) /* {{{ */
    3220             : {
    3221      345097 :         if (fbc) {
    3222      277070 :                 if (fbc->type == ZEND_INTERNAL_FUNCTION) {
    3223      265510 :                         if (init_op->opcode == ZEND_INIT_FCALL && !zend_execute_internal) {
    3224      262976 :                                 if (!(fbc->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED|ZEND_ACC_HAS_TYPE_HINTS|ZEND_ACC_RETURN_REFERENCE))) {
    3225      261634 :                                         return ZEND_DO_ICALL;
    3226             :                                 } else {
    3227        1342 :                                         return ZEND_DO_FCALL_BY_NAME;
    3228             :                                 }
    3229             :                         }
    3230             :                 } else {
    3231       11560 :                         if (zend_execute_ex == execute_ex && !(fbc->common.fn_flags & ZEND_ACC_ABSTRACT)) {
    3232       11545 :                                 return ZEND_DO_UCALL;
    3233             :                         }
    3234             :                 }
    3235      266771 :         } else if (zend_execute_ex == execute_ex &&
    3236       67971 :                    !zend_execute_internal &&
    3237       67971 :                    (init_op->opcode == ZEND_INIT_FCALL_BY_NAME ||
    3238       62802 :                     init_op->opcode == ZEND_INIT_NS_FCALL_BY_NAME)) {
    3239        5538 :                 return ZEND_DO_FCALL_BY_NAME;
    3240             :         }
    3241       65038 :         return ZEND_DO_FCALL;
    3242             : }
    3243             : /* }}} */
    3244             : 
    3245      345113 : void zend_compile_call_common(znode *result, zend_ast *args_ast, zend_function *fbc) /* {{{ */
    3246             : {
    3247             :         zend_op *opline;
    3248      345113 :         uint32_t opnum_init = get_next_op_number(CG(active_op_array)) - 1;
    3249             :         uint32_t arg_count;
    3250             :         uint32_t call_flags;
    3251             : 
    3252      345113 :         zend_do_extended_fcall_begin();
    3253             : 
    3254      345113 :         arg_count = zend_compile_args(args_ast, fbc);
    3255             : 
    3256      345097 :         opline = &CG(active_op_array)->opcodes[opnum_init];
    3257      345097 :         opline->extended_value = arg_count;
    3258             : 
    3259      345097 :         if (opline->opcode == ZEND_INIT_FCALL) {
    3260      271329 :                 opline->op1.num = zend_vm_calc_used_stack(arg_count, fbc);
    3261             :         }
    3262             : 
    3263      345097 :         call_flags = (opline->opcode == ZEND_NEW ? ZEND_CALL_CTOR : 0);
    3264      345097 :         opline = zend_emit_op(result, zend_get_call_op(opline, fbc), NULL, NULL);
    3265      345097 :         opline->op1.num = call_flags;
    3266             : 
    3267      345097 :         zend_do_extended_fcall_end();
    3268      345097 : }
    3269             : /* }}} */
    3270             : 
    3271      287360 : zend_bool zend_compile_function_name(znode *name_node, zend_ast *name_ast) /* {{{ */
    3272             : {
    3273      287360 :         zend_string *orig_name = zend_ast_get_str(name_ast);
    3274             :         zend_bool is_fully_qualified;
    3275             : 
    3276      287360 :         name_node->op_type = IS_CONST;
    3277      287360 :         ZVAL_STR(&name_node->u.constant, zend_resolve_function_name(
    3278             :                 orig_name, name_ast->attr, &is_fully_qualified));
    3279             : 
    3280      287360 :         return !is_fully_qualified && FC(current_namespace);
    3281             : }
    3282             : /* }}} */
    3283             : 
    3284         368 : void zend_compile_ns_call(znode *result, znode *name_node, zend_ast *args_ast) /* {{{ */
    3285             : {
    3286         368 :         zend_op *opline = get_next_op(CG(active_op_array));
    3287         368 :         opline->opcode = ZEND_INIT_NS_FCALL_BY_NAME;
    3288         368 :         SET_UNUSED(opline->op1);
    3289         368 :         opline->op2_type = IS_CONST;
    3290         368 :         opline->op2.constant = zend_add_ns_func_name_literal(
    3291             :                 CG(active_op_array), Z_STR(name_node->u.constant));
    3292         368 :         zend_alloc_cache_slot(opline->op2.constant);
    3293             : 
    3294         368 :         zend_compile_call_common(result, args_ast, NULL);
    3295         368 : }
    3296             : /* }}} */
    3297             : 
    3298        7392 : void zend_compile_dynamic_call(znode *result, znode *name_node, zend_ast *args_ast) /* {{{ */
    3299             : {
    3300       17771 :         if (name_node->op_type == IS_CONST && Z_TYPE(name_node->u.constant) == IS_STRING) {
    3301             :                 const char *colon;
    3302        5188 :                 zend_string *str = Z_STR(name_node->u.constant);
    3303       10378 :                 if ((colon = zend_memrchr(ZSTR_VAL(str), ':', ZSTR_LEN(str))) != NULL && colon > ZSTR_VAL(str) && *(colon - 1) == ':') {
    3304           4 :                         zend_string *class = zend_string_init(ZSTR_VAL(str), colon - ZSTR_VAL(str) - 1, 0);
    3305           4 :                         zend_string *method = zend_string_init(colon + 1, ZSTR_LEN(str) - (colon - ZSTR_VAL(str)) - 1, 0);
    3306           2 :                         zend_op *opline = get_next_op(CG(active_op_array));
    3307             : 
    3308           2 :                         opline->opcode = ZEND_INIT_STATIC_METHOD_CALL;
    3309           2 :                         opline->op1_type = IS_CONST;
    3310           2 :                         opline->op1.constant = zend_add_class_name_literal(CG(active_op_array), class);
    3311           2 :                         opline->op2_type = IS_CONST;
    3312           2 :                         opline->op2.constant = zend_add_func_name_literal(CG(active_op_array), method);
    3313           2 :                         zend_alloc_cache_slot(opline->op2.constant);
    3314           2 :                         zval_ptr_dtor(&name_node->u.constant);
    3315             :                 } else {
    3316        5186 :                         zend_op *opline = get_next_op(CG(active_op_array));
    3317             : 
    3318        5186 :                         opline->opcode = ZEND_INIT_FCALL_BY_NAME;
    3319        5186 :                         SET_UNUSED(opline->op1);
    3320        5186 :                         opline->op2_type = IS_CONST;
    3321        5186 :                         opline->op2.constant = zend_add_func_name_literal(CG(active_op_array), str);
    3322        5186 :                         zend_alloc_cache_slot(opline->op2.constant);
    3323             :                 }
    3324             :         } else {
    3325        2204 :                 zend_emit_op(NULL, ZEND_INIT_DYNAMIC_CALL, NULL, name_node);
    3326             :         }
    3327             : 
    3328        7392 :         zend_compile_call_common(result, args_ast, NULL);
    3329        7392 : }
    3330             : /* }}} */
    3331             : 
    3332         211 : static zend_bool zend_args_contain_unpack(zend_ast_list *args) /* {{{ */
    3333             : {
    3334             :         uint32_t i;
    3335         852 :         for (i = 0; i < args->children; ++i) {
    3336         641 :                 if (args->child[i]->kind == ZEND_AST_UNPACK) {
    3337           0 :                         return 1;
    3338             :                 }
    3339             :         }
    3340         211 :         return 0;
    3341             : }
    3342             : /* }}} */
    3343             : 
    3344        5180 : int zend_compile_func_strlen(znode *result, zend_ast_list *args) /* {{{ */
    3345             : {
    3346             :         znode arg_node;
    3347             : 
    3348       15530 :         if ((CG(compiler_options) & ZEND_COMPILE_NO_BUILTIN_STRLEN)
    3349       10350 :                 || args->children != 1 || args->child[0]->kind == ZEND_AST_UNPACK
    3350             :         ) {
    3351           8 :                 return FAILURE;
    3352             :         }
    3353             : 
    3354        5172 :         zend_compile_expr(&arg_node, args->child[0]);
    3355        5322 :         if (arg_node.op_type == IS_CONST && Z_TYPE(arg_node.u.constant) == IS_STRING) {
    3356          73 :                 result->op_type = IS_CONST;
    3357          73 :                 ZVAL_LONG(&result->u.constant, Z_STRLEN(arg_node.u.constant));
    3358             :                 zval_dtor(&arg_node.u.constant);
    3359             :         } else {
    3360        5099 :                 zend_emit_op_tmp(result, ZEND_STRLEN, &arg_node, NULL);
    3361             :         }
    3362        5172 :         return SUCCESS;
    3363             : }
    3364             : /* }}} */
    3365             : 
    3366        4353 : int zend_compile_func_typecheck(znode *result, zend_ast_list *args, uint32_t type) /* {{{ */
    3367             : {
    3368             :         znode arg_node;
    3369             :         zend_op *opline;
    3370             : 
    3371        4353 :         if (args->children != 1 || args->child[0]->kind == ZEND_AST_UNPACK) {
    3372          24 :                 return FAILURE;
    3373             :         }
    3374             : 
    3375        4329 :         zend_compile_expr(&arg_node, args->child[0]);
    3376        4329 :         opline = zend_emit_op_tmp(result, ZEND_TYPE_CHECK, &arg_node, NULL);
    3377        4329 :         opline->extended_value = type;
    3378        4329 :         return SUCCESS;
    3379             : }
    3380             : /* }}} */
    3381             : 
    3382         212 : int zend_compile_func_defined(znode *result, zend_ast_list *args) /* {{{ */
    3383             : {
    3384             :         zend_string *name;
    3385             :         zend_op *opline;
    3386             : 
    3387         212 :         if (args->children != 1 || args->child[0]->kind != ZEND_AST_ZVAL) {
    3388           1 :                 return FAILURE;
    3389             :         }
    3390             : 
    3391         422 :         name = zval_get_string(zend_ast_get_zval(args->child[0]));
    3392         633 :         if (zend_memrchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name)) || zend_memrchr(ZSTR_VAL(name), ':', ZSTR_LEN(name))) {
    3393             :                 zend_string_release(name);
    3394           8 :                 return FAILURE;
    3395             :         }
    3396             : 
    3397         203 :         if (zend_try_ct_eval_const(&result->u.constant, name, 0)) {
    3398             :                 zend_string_release(name);
    3399         154 :                 zval_ptr_dtor(&result->u.constant);
    3400         154 :                 ZVAL_TRUE(&result->u.constant);
    3401         154 :                 result->op_type = IS_CONST;
    3402         154 :                 return SUCCESS;
    3403             :         }
    3404             : 
    3405          49 :         opline = zend_emit_op_tmp(result, ZEND_DEFINED, NULL, NULL);
    3406          49 :         opline->op1_type = IS_CONST;
    3407          49 :         LITERAL_STR(opline->op1, name);
    3408          49 :         zend_alloc_cache_slot(opline->op1.constant);
    3409             : 
    3410             :         /* Lowercase constant name in a separate literal */
    3411             :         {
    3412             :                 zval c;
    3413          49 :                 zend_string *lcname = zend_string_tolower(name);
    3414          49 :                 ZVAL_NEW_STR(&c, lcname);
    3415          49 :                 zend_add_literal(CG(active_op_array), &c);
    3416             :         }
    3417          49 :         return SUCCESS;
    3418             : }
    3419             : /* }}} */
    3420             : 
    3421         625 : int zend_compile_func_chr(znode *result, zend_ast_list *args) /* {{{ */
    3422             : {
    3423             : 
    3424        1759 :         if (args->children == 1 &&
    3425         621 :             args->child[0]->kind == ZEND_AST_ZVAL &&
    3426         513 :             Z_TYPE_P(zend_ast_get_zval(args->child[0])) == IS_LONG) {
    3427             : 
    3428        1026 :                 zend_long c = Z_LVAL_P(zend_ast_get_zval(args->child[0])) & 0xff;
    3429             : 
    3430         513 :                 result->op_type = IS_CONST;
    3431         513 :                 if (CG(one_char_string)[c]) {
    3432           0 :                         ZVAL_INTERNED_STR(&result->u.constant, CG(one_char_string)[c]);
    3433             :                 } else {
    3434        1026 :                         ZVAL_NEW_STR(&result->u.constant, zend_string_alloc(1, 0));
    3435         513 :                         Z_STRVAL_P(&result->u.constant)[0] = (char)c;
    3436         513 :                         Z_STRVAL_P(&result->u.constant)[1] = '\0';
    3437             :                 }
    3438         513 :                 return SUCCESS;
    3439             :         } else {
    3440         112 :                 return FAILURE;
    3441             :         }
    3442             : }
    3443             : /* }}} */
    3444             : 
    3445          68 : int zend_compile_func_ord(znode *result, zend_ast_list *args) /* {{{ */
    3446             : {
    3447         152 :         if (args->children == 1 &&
    3448          64 :             args->child[0]->kind == ZEND_AST_ZVAL &&
    3449          20 :             Z_TYPE_P(zend_ast_get_zval(args->child[0])) == IS_STRING) {
    3450             : 
    3451          17 :                 result->op_type = IS_CONST;
    3452          34 :                 ZVAL_LONG(&result->u.constant, (unsigned char)Z_STRVAL_P(zend_ast_get_zval(args->child[0]))[0]);
    3453          17 :                 return SUCCESS;
    3454             :         } else {
    3455          51 :                 return FAILURE;
    3456             :         }
    3457             : }
    3458             : /* }}} */
    3459             : 
    3460             : 
    3461         211 : static int zend_try_compile_ct_bound_init_user_func(zend_ast *name_ast, uint32_t num_args) /* {{{ */
    3462             : {
    3463             :         zend_string *name, *lcname;
    3464             :         zend_function *fbc;
    3465             :         zend_op *opline;
    3466             : 
    3467         284 :         if (name_ast->kind != ZEND_AST_ZVAL || Z_TYPE_P(zend_ast_get_zval(name_ast)) != IS_STRING) {
    3468         138 :                 return FAILURE;
    3469             :         }
    3470             : 
    3471          73 :         name = zend_ast_get_str(name_ast);
    3472          73 :         lcname = zend_string_tolower(name);
    3473             : 
    3474         146 :         fbc = zend_hash_find_ptr(CG(function_table), lcname);
    3475         226 :         if (!fbc
    3476          71 :          || (fbc->type == ZEND_INTERNAL_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS))
    3477          82 :          || (fbc->type == ZEND_USER_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_USER_FUNCTIONS))
    3478             :         ) {
    3479             :                 zend_string_release(lcname);
    3480          22 :                 return FAILURE;
    3481             :         }
    3482             : 
    3483          51 :         opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, NULL);
    3484          51 :         opline->extended_value = num_args;
    3485          51 :         opline->op1.num = zend_vm_calc_used_stack(num_args, fbc);
    3486          51 :         opline->op2_type = IS_CONST;
    3487          51 :         LITERAL_STR(opline->op2, lcname);
    3488          51 :         zend_alloc_cache_slot(opline->op2.constant);
    3489             : 
    3490          51 :         return SUCCESS;
    3491             : }
    3492             : /* }}} */
    3493             : 
    3494         211 : static void zend_compile_init_user_func(zend_ast *name_ast, uint32_t num_args, zend_string *orig_func_name) /* {{{ */
    3495             : {
    3496             :         zend_op *opline;
    3497             :         znode name_node;
    3498             : 
    3499         211 :         if (zend_try_compile_ct_bound_init_user_func(name_ast, num_args) == SUCCESS) {
    3500          51 :                 return;
    3501             :         }
    3502             : 
    3503         160 :         zend_compile_expr(&name_node, name_ast);
    3504             : 
    3505         160 :         opline = zend_emit_op(NULL, ZEND_INIT_USER_CALL, NULL, &name_node);
    3506         160 :         opline->op1_type = IS_CONST;
    3507         320 :         LITERAL_STR(opline->op1, zend_string_copy(orig_func_name));
    3508         160 :         opline->extended_value = num_args;
    3509             : }
    3510             : /* }}} */
    3511             : 
    3512             : /* cufa = call_user_func_array */
    3513          73 : int zend_compile_func_cufa(znode *result, zend_ast_list *args, zend_string *lcname) /* {{{ */
    3514             : {
    3515             :         znode arg_node;
    3516             : 
    3517          73 :         if (args->children != 2 || zend_args_contain_unpack(args)) {
    3518           0 :                 return FAILURE;
    3519             :         }
    3520             : 
    3521          73 :         zend_compile_init_user_func(args->child[0], 0, lcname);
    3522          73 :         zend_compile_expr(&arg_node, args->child[1]);
    3523          73 :         zend_emit_op(NULL, ZEND_SEND_ARRAY, &arg_node, NULL);
    3524          73 :         zend_emit_op(result, ZEND_DO_FCALL, NULL, NULL);
    3525             : 
    3526          73 :         return SUCCESS;
    3527             : }
    3528             : /* }}} */
    3529             : 
    3530             : /* cuf = call_user_func */
    3531         138 : int zend_compile_func_cuf(znode *result, zend_ast_list *args, zend_string *lcname) /* {{{ */
    3532             : {
    3533             :         uint32_t i;
    3534             : 
    3535         138 :         if (args->children < 1 || zend_args_contain_unpack(args)) {
    3536           0 :                 return FAILURE;
    3537             :         }
    3538             : 
    3539         138 :         zend_compile_init_user_func(args->child[0], args->children - 1, lcname);
    3540         495 :         for (i = 1; i < args->children; ++i) {
    3541         357 :                 zend_ast *arg_ast = args->child[i];
    3542             :                 znode arg_node;
    3543             :                 zend_op *opline;
    3544             : 
    3545         357 :                 zend_compile_expr(&arg_node, arg_ast);
    3546         357 :                 if (arg_node.op_type & (IS_VAR|IS_CV)) {
    3547         273 :                         opline = zend_emit_op(NULL, ZEND_SEND_USER, &arg_node, NULL);
    3548             :                 } else {
    3549          84 :                         opline = zend_emit_op(NULL, ZEND_SEND_VAL, &arg_node, NULL);
    3550             :                 }
    3551             : 
    3552         357 :                 opline->op2.num = i;
    3553         357 :                 opline->result.var = (uint32_t)(zend_intptr_t)ZEND_CALL_ARG(NULL, i);
    3554             :         }
    3555         138 :         zend_emit_op(result, ZEND_DO_FCALL, NULL, NULL);
    3556             : 
    3557         138 :         return SUCCESS;
    3558             : }
    3559             : /* }}} */
    3560             : 
    3561         240 : static int zend_compile_assert(znode *result, zend_ast_list *args, zend_string *name, zend_function *fbc) /* {{{ */
    3562             : {
    3563         240 :         if (EG(assertions) >= 0) {
    3564             :                 znode name_node;
    3565             :                 zend_op *opline;
    3566         232 :                 uint32_t check_op_number = get_next_op_number(CG(active_op_array));
    3567             : 
    3568         232 :                 zend_emit_op(NULL, ZEND_ASSERT_CHECK, NULL, NULL);
    3569             : 
    3570         232 :                 if (fbc) {
    3571         225 :                         name_node.op_type = IS_CONST;
    3572         225 :                         ZVAL_STR_COPY(&name_node.u.constant, name);
    3573             : 
    3574         225 :                         opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, &name_node);
    3575             :                 } else {
    3576           7 :                         opline = zend_emit_op(NULL, ZEND_INIT_NS_FCALL_BY_NAME, NULL, NULL);
    3577           7 :                         opline->op2_type = IS_CONST;
    3578           7 :                         opline->op2.constant = zend_add_ns_func_name_literal(
    3579             :                                 CG(active_op_array), name);
    3580             :                 }
    3581         232 :                 zend_alloc_cache_slot(opline->op2.constant);
    3582             : 
    3583         519 :                 if (args->children == 1 &&
    3584         218 :                     (args->child[0]->kind != ZEND_AST_ZVAL ||
    3585          69 :                      Z_TYPE_P(zend_ast_get_zval(args->child[0])) != IS_STRING)) {
    3586             :                         /* add "assert(condition) as assertion message */
    3587         320 :                         zend_ast_list_add((zend_ast*)args,
    3588             :                                 zend_ast_create_zval_from_str(
    3589             :                                         zend_ast_export("assert(", args->child[0], ")")));
    3590             :                 }
    3591             : 
    3592         232 :                 zend_compile_call_common(result, (zend_ast*)args, fbc);
    3593             : 
    3594         232 :                 opline = &CG(active_op_array)->opcodes[check_op_number];
    3595         232 :                 opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    3596         232 :                 SET_NODE(opline->result, result);
    3597             :         } else {
    3598           8 :                 if (!fbc) {
    3599             :                         zend_string_release(name);
    3600             :                 }
    3601           8 :                 result->op_type = IS_CONST;
    3602           8 :                 ZVAL_TRUE(&result->u.constant);
    3603             :         }
    3604             : 
    3605         240 :         return SUCCESS;
    3606             : }
    3607             : /* }}} */
    3608             : 
    3609      281796 : int zend_try_compile_special_func(znode *result, zend_string *lcname, zend_ast_list *args, zend_function *fbc, uint32_t type) /* {{{ */
    3610             : {
    3611      281796 :         if (fbc->internal_function.handler == ZEND_FN(display_disabled_function)) {
    3612           6 :                 return FAILURE;
    3613             :         }
    3614             : 
    3615      281790 :         if (zend_string_equals_literal(lcname, "assert")) {
    3616         231 :                 return zend_compile_assert(result, args, lcname, fbc);
    3617             :         }
    3618             : 
    3619      281559 :         if (CG(compiler_options) & ZEND_COMPILE_NO_BUILTINS) {
    3620           0 :                 return FAILURE;
    3621             :         }
    3622             : 
    3623      281559 :         if (zend_string_equals_literal(lcname, "strlen")) {
    3624        5180 :                 return zend_compile_func_strlen(result, args);
    3625      276379 :         } else if (zend_string_equals_literal(lcname, "is_null")) {
    3626         876 :                 return zend_compile_func_typecheck(result, args, IS_NULL);
    3627      275503 :         } else if (zend_string_equals_literal(lcname, "is_bool")) {
    3628          23 :                 return zend_compile_func_typecheck(result, args, _IS_BOOL);
    3629      913583 :         } else if (zend_string_equals_literal(lcname, "is_long")
    3630      350978 :                 || zend_string_equals_literal(lcname, "is_int")
    3631      287125 :                 || zend_string_equals_literal(lcname, "is_integer")
    3632             :         ) {
    3633         342 :                 return zend_compile_func_typecheck(result, args, IS_LONG);
    3634      862120 :         } else if (zend_string_equals_literal(lcname, "is_float")
    3635      286737 :                 || zend_string_equals_literal(lcname, "is_double")
    3636      300245 :                 || zend_string_equals_literal(lcname, "is_real")
    3637             :         ) {
    3638          35 :                 return zend_compile_func_typecheck(result, args, IS_DOUBLE);
    3639      275103 :         } else if (zend_string_equals_literal(lcname, "is_string")) {
    3640        1502 :                 return zend_compile_func_typecheck(result, args, IS_STRING);
    3641      273601 :         } else if (zend_string_equals_literal(lcname, "is_array")) {
    3642         818 :                 return zend_compile_func_typecheck(result, args, IS_ARRAY);
    3643      272783 :         } else if (zend_string_equals_literal(lcname, "is_object")) {
    3644         525 :                 return zend_compile_func_typecheck(result, args, IS_OBJECT);
    3645      272258 :         } else if (zend_string_equals_literal(lcname, "is_resource")) {
    3646         232 :                 return zend_compile_func_typecheck(result, args, IS_RESOURCE);
    3647      272026 :         } else if (zend_string_equals_literal(lcname, "defined")) {
    3648         212 :                 return zend_compile_func_defined(result, args);
    3649      271814 :         } else if (zend_string_equals_literal(lcname, "chr") && type == BP_VAR_R) {
    3650         625 :                 return zend_compile_func_chr(result, args);
    3651      271189 :         } else if (zend_string_equals_literal(lcname, "ord") && type == BP_VAR_R) {
    3652          68 :                 return zend_compile_func_ord(result, args);
    3653      271121 :         } else if (zend_string_equals_literal(lcname, "call_user_func_array")) {
    3654          73 :                 return zend_compile_func_cufa(result, args, lcname);
    3655      271048 :         } else if (zend_string_equals_literal(lcname, "call_user_func")) {
    3656         138 :                 return zend_compile_func_cuf(result, args, lcname);
    3657             :         } else {
    3658      270910 :                 return FAILURE;
    3659             :         }
    3660             : }
    3661             : /* }}} */
    3662             : 
    3663      289565 : void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    3664             : {
    3665      289565 :         zend_ast *name_ast = ast->child[0];
    3666      289565 :         zend_ast *args_ast = ast->child[1];
    3667             : 
    3668             :         znode name_node;
    3669             : 
    3670      576925 :         if (name_ast->kind != ZEND_AST_ZVAL || Z_TYPE_P(zend_ast_get_zval(name_ast)) != IS_STRING) {
    3671        2205 :                 zend_compile_expr(&name_node, name_ast);
    3672        2205 :                 zend_compile_dynamic_call(result, &name_node, args_ast);
    3673        2205 :                 return;
    3674             :         }
    3675             : 
    3676             :         {
    3677      287360 :                 zend_bool runtime_resolution = zend_compile_function_name(&name_node, name_ast);
    3678      287360 :                 if (runtime_resolution) {
    3679         424 :                         if (zend_string_equals_literal_ci(zend_ast_get_str(name_ast), "assert")) {
    3680          18 :                                 zend_compile_assert(result, zend_ast_get_list(args_ast), Z_STR(name_node.u.constant), NULL);
    3681             :                         } else {
    3682         368 :                                 zend_compile_ns_call(result, &name_node, args_ast);
    3683             :                         }
    3684         377 :                         return;
    3685             :                 }
    3686             :         }
    3687             : 
    3688             :         {
    3689      286983 :                 zval *name = &name_node.u.constant;
    3690             :                 zend_string *lcname;
    3691             :                 zend_function *fbc;
    3692             :                 zend_op *opline;
    3693             : 
    3694      286983 :                 lcname = zend_string_tolower(Z_STR_P(name));
    3695             : 
    3696      573966 :                 fbc = zend_hash_find_ptr(CG(function_table), lcname);
    3697     1132371 :                 if (!fbc
    3698      555234 :                  || (fbc->type == ZEND_INTERNAL_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS))
    3699      290154 :                  || (fbc->type == ZEND_USER_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_USER_FUNCTIONS))
    3700             :                 ) {
    3701             :                         zend_string_release(lcname);
    3702        5187 :                         zend_compile_dynamic_call(result, &name_node, args_ast);
    3703        5187 :                         return;
    3704             :                 }
    3705             : 
    3706      281796 :                 if (zend_try_compile_special_func(result, lcname,
    3707             :                                 zend_ast_get_list(args_ast), fbc, type) == SUCCESS
    3708             :                 ) {
    3709             :                         zend_string_release(lcname);
    3710       10676 :                         zval_ptr_dtor(&name_node.u.constant);
    3711       10676 :                         return;
    3712             :                 }
    3713             : 
    3714      271120 :                 zval_ptr_dtor(&name_node.u.constant);
    3715      271120 :                 ZVAL_NEW_STR(&name_node.u.constant, lcname);
    3716             : 
    3717      271120 :                 opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, &name_node);
    3718      271120 :                 zend_alloc_cache_slot(opline->op2.constant);
    3719             : 
    3720      271120 :                 zend_compile_call_common(result, args_ast, fbc);
    3721             :         }
    3722             : }
    3723             : /* }}} */
    3724             : 
    3725       38861 : void zend_compile_method_call(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    3726             : {
    3727       38861 :         zend_ast *obj_ast = ast->child[0];
    3728       38861 :         zend_ast *method_ast = ast->child[1];
    3729       38861 :         zend_ast *args_ast = ast->child[2];
    3730             : 
    3731             :         znode obj_node, method_node;
    3732             :         zend_op *opline;
    3733       38861 :         zend_function *fbc = NULL;
    3734             : 
    3735       38861 :         if (is_this_fetch(obj_ast)) {
    3736        1432 :                 obj_node.op_type = IS_UNUSED;
    3737             :         } else {
    3738       37429 :                 zend_compile_expr(&obj_node, obj_ast);
    3739             :         }
    3740             : 
    3741       38861 :         zend_compile_expr(&method_node, method_ast);
    3742       38861 :         opline = zend_emit_op(NULL, ZEND_INIT_METHOD_CALL, &obj_node, NULL);
    3743             : 
    3744       38861 :         if (method_node.op_type == IS_CONST) {
    3745       38833 :                 if (Z_TYPE(method_node.u.constant) != IS_STRING) {
    3746           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Method name must be a string");
    3747             :                 }
    3748             : 
    3749       38831 :                 opline->op2_type = IS_CONST;
    3750       38831 :                 opline->op2.constant = zend_add_func_name_literal(CG(active_op_array),
    3751             :                         Z_STR(method_node.u.constant));
    3752       38831 :                 zend_alloc_polymorphic_cache_slot(opline->op2.constant);
    3753             :         } else {
    3754          28 :                 SET_NODE(opline->op2, &method_node);
    3755             :         }
    3756             : 
    3757             :         /* Check if this calls a known method on $this */
    3758       41715 :         if (opline->op1_type == IS_UNUSED && opline->op2_type == IS_CONST &&
    3759        2856 :                         CG(active_class_entry) && zend_is_scope_known()) {
    3760        1422 :                 zend_string *lcname = Z_STR_P(CT_CONSTANT(opline->op2) + 1);
    3761        2844 :                 fbc = zend_hash_find_ptr(&CG(active_class_entry)->function_table, lcname);
    3762             : 
    3763             :                 /* We only know the exact method that is being called if it is either private or final.
    3764             :                  * Otherwise an overriding method in a child class may be called. */
    3765        1422 :                 if (fbc && !(fbc->common.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_FINAL))) {
    3766          87 :                         fbc = NULL;
    3767             :                 }
    3768             :         }
    3769             : 
    3770       38859 :         zend_compile_call_common(result, args_ast, fbc);
    3771       38859 : }
    3772             : /* }}} */
    3773             : 
    3774       11669 : static zend_bool zend_is_constructor(zend_string *name) /* {{{ */
    3775             : {
    3776       11669 :         return zend_string_equals_literal_ci(name, ZEND_CONSTRUCTOR_FUNC_NAME);
    3777             : }
    3778             : /* }}} */
    3779             : 
    3780       11705 : void zend_compile_static_call(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    3781             : {
    3782       11705 :         zend_ast *class_ast = ast->child[0];
    3783       11705 :         zend_ast *method_ast = ast->child[1];
    3784       11705 :         zend_ast *args_ast = ast->child[2];
    3785             : 
    3786             :         znode class_node, method_node;
    3787             :         zend_op *opline;
    3788       11705 :         zend_function *fbc = NULL;
    3789             : 
    3790       11705 :         zend_compile_class_ref_ex(&class_node, class_ast, ZEND_FETCH_CLASS_EXCEPTION);
    3791             : 
    3792       11705 :         zend_compile_expr(&method_node, method_ast);
    3793       11705 :         if (method_node.op_type == IS_CONST) {
    3794       11669 :                 zval *name = &method_node.u.constant;
    3795       11669 :                 if (Z_TYPE_P(name) != IS_STRING) {
    3796           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Method name must be a string");
    3797             :                 }
    3798       11669 :                 if (zend_is_constructor(Z_STR_P(name))) {
    3799        1058 :                         zval_ptr_dtor(name);
    3800        1058 :                         method_node.op_type = IS_UNUSED;
    3801             :                 }
    3802             :         }
    3803             : 
    3804       11705 :         opline = get_next_op(CG(active_op_array));
    3805       11705 :         opline->opcode = ZEND_INIT_STATIC_METHOD_CALL;
    3806             : 
    3807       11705 :         zend_set_class_name_op1(opline, &class_node);
    3808             : 
    3809       11705 :         if (method_node.op_type == IS_CONST) {
    3810       10611 :                 opline->op2_type = IS_CONST;
    3811       10611 :                 opline->op2.constant = zend_add_func_name_literal(CG(active_op_array),
    3812             :                         Z_STR(method_node.u.constant));
    3813       10611 :                 if (opline->op1_type == IS_CONST) {
    3814        6170 :                         zend_alloc_cache_slot(opline->op2.constant);
    3815             :                 } else {
    3816        4441 :                         zend_alloc_polymorphic_cache_slot(opline->op2.constant);
    3817             :                 }
    3818             :         } else {
    3819        1094 :                 SET_NODE(opline->op2, &method_node);
    3820             :         }
    3821       11705 :         zend_check_live_ranges(opline);
    3822             : 
    3823             :         /* Check if we already know which method we're calling */
    3824       11705 :         if (opline->op2_type == IS_CONST) {
    3825       10611 :                 zend_class_entry *ce = NULL;
    3826       10611 :                 if (opline->op1_type == IS_CONST) {
    3827        6170 :                         zend_string *lcname = Z_STR_P(CT_CONSTANT(opline->op1) + 1);
    3828       12340 :                         ce = zend_hash_find_ptr(CG(class_table), lcname);
    3829        8430 :                         if (!ce && CG(active_class_entry)
    3830        2260 :                                         && zend_string_equals_ci(CG(active_class_entry)->name, lcname)) {
    3831        1113 :                                 ce = CG(active_class_entry);
    3832             :                         }
    3833       12061 :                 } else if (opline->op1_type == IS_UNUSED
    3834        8863 :                                 && (opline->op1.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_SELF
    3835        3198 :                                 && zend_is_scope_known()) {
    3836        3194 :                         ce = CG(active_class_entry);
    3837             :                 }
    3838       10611 :                 if (ce) {
    3839        7646 :                         zend_string *lcname = Z_STR_P(CT_CONSTANT(opline->op2) + 1);
    3840       15292 :                         fbc = zend_hash_find_ptr(&ce->function_table, lcname);
    3841             :                 }
    3842             :         }
    3843             : 
    3844       11705 :         zend_compile_call_common(result, args_ast, fbc);
    3845       11705 : }
    3846             : /* }}} */
    3847             : 
    3848             : void zend_compile_class_decl(zend_ast *ast);
    3849             : 
    3850       15437 : void zend_compile_new(znode *result, zend_ast *ast) /* {{{ */
    3851             : {
    3852       15437 :         zend_ast *class_ast = ast->child[0];
    3853       15437 :         zend_ast *args_ast = ast->child[1];
    3854             : 
    3855             :         znode class_node, ctor_result;
    3856             :         zend_op *opline;
    3857             :         uint32_t opnum;
    3858             : 
    3859       15437 :         if (class_ast->kind == ZEND_AST_CLASS) {
    3860          29 :                 uint32_t dcl_opnum = get_next_op_number(CG(active_op_array));
    3861          29 :                 zend_compile_class_decl(class_ast);
    3862             :                 /* jump over anon class declaration */
    3863          29 :                 opline = &CG(active_op_array)->opcodes[dcl_opnum];
    3864          29 :                 if (opline->opcode == ZEND_FETCH_CLASS) {
    3865           3 :                         opline++;
    3866             :                 }
    3867          29 :                 class_node.op_type = opline->result_type;
    3868          29 :                 class_node.u.op.var = opline->result.var;
    3869          29 :                 opline->extended_value = get_next_op_number(CG(active_op_array));
    3870             :         } else {
    3871       15408 :                 zend_compile_class_ref_ex(&class_node, class_ast, ZEND_FETCH_CLASS_EXCEPTION);
    3872             :         }
    3873             : 
    3874       15437 :         opnum = get_next_op_number(CG(active_op_array));
    3875       15437 :         opline = zend_emit_op(result, ZEND_NEW, NULL, NULL);
    3876             : 
    3877       15437 :         if (class_node.op_type == IS_CONST) {
    3878       13939 :                 opline->op1_type = IS_CONST;
    3879       13939 :                 opline->op1.constant = zend_add_class_name_literal(
    3880             :                         CG(active_op_array), Z_STR(class_node.u.constant));
    3881             :         } else {
    3882        1498 :                 SET_NODE(opline->op1, &class_node);
    3883             :         }
    3884             : 
    3885       15437 :         zend_compile_call_common(&ctor_result, args_ast, NULL);
    3886       15437 :         zend_do_free(&ctor_result);
    3887             : 
    3888             :         /* We save the position of DO_FCALL for convenience in find_live_range().
    3889             :          * This info is not preserved for runtime. */
    3890       15437 :         opline = &CG(active_op_array)->opcodes[opnum];
    3891       15437 :         opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    3892       15437 : }
    3893             : /* }}} */
    3894             : 
    3895         122 : void zend_compile_clone(znode *result, zend_ast *ast) /* {{{ */
    3896             : {
    3897         122 :         zend_ast *obj_ast = ast->child[0];
    3898             : 
    3899             :         znode obj_node;
    3900         122 :         zend_compile_expr(&obj_node, obj_ast);
    3901             : 
    3902         122 :         zend_emit_op_tmp(result, ZEND_CLONE, &obj_node, NULL);
    3903         122 : }
    3904             : /* }}} */
    3905             : 
    3906        5171 : void zend_compile_global_var(zend_ast *ast) /* {{{ */
    3907             : {
    3908        5171 :         zend_ast *var_ast = ast->child[0];
    3909        5171 :         zend_ast *name_ast = var_ast->child[0];
    3910             : 
    3911             :         znode name_node, result;
    3912             : 
    3913        5171 :         zend_compile_expr(&name_node, name_ast);
    3914        5171 :         if (name_node.op_type == IS_CONST) {
    3915        5168 :                 convert_to_string(&name_node.u.constant);
    3916             :         }
    3917             : 
    3918        5171 :         if (is_this_fetch(var_ast)) {
    3919           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as global variable");
    3920        5170 :         } else if (zend_try_compile_cv(&result, var_ast) == SUCCESS) {
    3921        5167 :                 zend_op *opline = zend_emit_op(NULL, ZEND_BIND_GLOBAL, &result, &name_node);
    3922        5167 :                 zend_alloc_cache_slot(opline->op2.constant);
    3923             :         } else {
    3924             :                 /* name_ast should be evaluated only. FETCH_GLOBAL_LOCK instructs FETCH_W
    3925             :                  * to not free the name_node operand, so it can be reused in the following
    3926             :                  * ASSIGN_REF, which then frees it. */
    3927           3 :                 zend_op *opline = zend_emit_op(&result, ZEND_FETCH_W, &name_node, NULL);
    3928           3 :                 opline->extended_value = ZEND_FETCH_GLOBAL_LOCK;
    3929             : 
    3930           3 :                 if (name_node.op_type == IS_CONST) {
    3931           0 :                         zend_string_addref(Z_STR(name_node.u.constant));
    3932             :                 }
    3933             : 
    3934           3 :                 zend_emit_assign_ref_znode(
    3935             :                         zend_ast_create(ZEND_AST_VAR, zend_ast_create_znode(&name_node)),
    3936             :                         &result
    3937             :                 );
    3938             :         }
    3939        5170 : }
    3940             : /* }}} */
    3941             : 
    3942        2323 : static void zend_compile_static_var_common(zend_ast *var_ast, zval *value, zend_bool by_ref) /* {{{ */
    3943             : {
    3944             :         znode var_node;
    3945             :         zend_op *opline;
    3946             : 
    3947        2323 :         zend_compile_expr(&var_node, var_ast);
    3948             : 
    3949        2323 :         if (!CG(active_op_array)->static_variables) {
    3950        2288 :                 if (CG(active_op_array)->scope) {
    3951        1110 :                         CG(active_op_array)->scope->ce_flags |= ZEND_HAS_STATIC_IN_METHODS;
    3952             :                 }
    3953        2288 :                 ALLOC_HASHTABLE(CG(active_op_array)->static_variables);
    3954        2288 :                 zend_hash_init(CG(active_op_array)->static_variables, 8, NULL, ZVAL_PTR_DTOR, 0);
    3955             :         }
    3956             : 
    3957        2323 :         if (GC_REFCOUNT(CG(active_op_array)->static_variables) > 1) {
    3958           0 :                 if (!(GC_FLAGS(CG(active_op_array)->static_variables) & IS_ARRAY_IMMUTABLE)) {
    3959           0 :                         GC_REFCOUNT(CG(active_op_array)->static_variables)--;
    3960             :                 }
    3961           0 :                 CG(active_op_array)->static_variables = zend_array_dup(CG(active_op_array)->static_variables);
    3962             :         }
    3963        2323 :         zend_hash_update(CG(active_op_array)->static_variables, Z_STR(var_node.u.constant), value);
    3964             : 
    3965        2323 :         if (zend_string_equals_literal(Z_STR(var_node.u.constant), "this")) {
    3966           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as static variable");
    3967             :         }
    3968             : 
    3969        2322 :         opline = zend_emit_op(NULL, ZEND_BIND_STATIC, NULL, &var_node);
    3970        2322 :         opline->op1_type = IS_CV;
    3971        4644 :         opline->op1.var = lookup_cv(CG(active_op_array), zend_string_copy(Z_STR(var_node.u.constant)));
    3972        2322 :         opline->extended_value = by_ref;
    3973        2322 : }
    3974             : /* }}} */
    3975             : 
    3976        2128 : void zend_compile_static_var(zend_ast *ast) /* {{{ */
    3977             : {
    3978        2128 :         zend_ast *var_ast = ast->child[0];
    3979        2128 :         zend_ast *value_ast = ast->child[1];
    3980             :         zval value_zv;
    3981             : 
    3982        2128 :         if (value_ast) {
    3983        2107 :                 zend_const_expr_to_zval(&value_zv, value_ast);
    3984             :         } else {
    3985          21 :                 ZVAL_NULL(&value_zv);
    3986             :         }
    3987             : 
    3988        2128 :         zend_compile_static_var_common(var_ast, &value_zv, 1);
    3989        2127 : }
    3990             : /* }}} */
    3991             : 
    3992        1685 : void zend_compile_unset(zend_ast *ast) /* {{{ */
    3993             : {
    3994        1685 :         zend_ast *var_ast = ast->child[0];
    3995             :         znode var_node;
    3996             :         zend_op *opline;
    3997             : 
    3998        1685 :         zend_ensure_writable_variable(var_ast);
    3999             : 
    4000        1684 :         switch (var_ast->kind) {
    4001             :                 case ZEND_AST_VAR:
    4002        1335 :                         if (is_this_fetch(var_ast)) {
    4003           2 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot unset $this");
    4004        1333 :                         } else if (zend_try_compile_cv(&var_node, var_ast) == SUCCESS) {
    4005        1323 :                                 opline = zend_emit_op(NULL, ZEND_UNSET_VAR, &var_node, NULL);
    4006        1323 :                                 opline->extended_value = ZEND_FETCH_LOCAL | ZEND_QUICK_SET;
    4007             :                         } else {
    4008          10 :                                 opline = zend_compile_simple_var_no_cv(NULL, var_ast, BP_VAR_UNSET, 0);
    4009          10 :                                 opline->opcode = ZEND_UNSET_VAR;
    4010             :                         }
    4011        1333 :                         return;
    4012             :                 case ZEND_AST_DIM:
    4013         253 :                         opline = zend_compile_dim_common(NULL, var_ast, BP_VAR_UNSET);
    4014         252 :                         opline->opcode = ZEND_UNSET_DIM;
    4015         252 :                         return;
    4016             :                 case ZEND_AST_PROP:
    4017          93 :                         opline = zend_compile_prop_common(NULL, var_ast, BP_VAR_UNSET);
    4018          93 :                         opline->opcode = ZEND_UNSET_OBJ;
    4019          93 :                         return;
    4020             :                 case ZEND_AST_STATIC_PROP:
    4021           3 :                         opline = zend_compile_static_prop_common(NULL, var_ast, BP_VAR_UNSET, 0);
    4022           3 :                         opline->opcode = ZEND_UNSET_STATIC_PROP;
    4023           3 :                         return;
    4024             :                 EMPTY_SWITCH_DEFAULT_CASE()
    4025             :         }
    4026             : }
    4027             : /* }}} */
    4028             : 
    4029       48644 : static int zend_handle_loops_and_finally_ex(zend_long depth, znode *return_value) /* {{{ */
    4030             : {
    4031             :         zend_loop_var *base;
    4032       48644 :         zend_loop_var *loop_var = zend_stack_top(&CG(loop_var_stack));
    4033             : 
    4034       48644 :         if (!loop_var) {
    4035         722 :                 return 1;
    4036             :         }
    4037       47922 :         base = zend_stack_base(&CG(loop_var_stack));
    4038       51064 :         for (; loop_var >= base; loop_var--) {
    4039       51046 :                 if (loop_var->opcode == ZEND_FAST_CALL) {
    4040          61 :                         zend_op *opline = get_next_op(CG(active_op_array));
    4041             : 
    4042          61 :                         opline->opcode = ZEND_FAST_CALL;
    4043          61 :                         opline->result_type = IS_TMP_VAR;
    4044          61 :                         opline->result.var = loop_var->var_num;
    4045          61 :                         SET_UNUSED(opline->op1);
    4046          61 :                         if (return_value) {
    4047          15 :                                 SET_NODE(opline->op2, return_value);
    4048             :                         } else {
    4049          46 :                                 SET_UNUSED(opline->op2);
    4050             :                         }
    4051          61 :                         opline->op1.num = loop_var->u.try_catch_offset;
    4052       50985 :                 } else if (loop_var->opcode == ZEND_DISCARD_EXCEPTION) {
    4053          34 :                         zend_op *opline = get_next_op(CG(active_op_array));
    4054          34 :                         opline->opcode = ZEND_DISCARD_EXCEPTION;
    4055          34 :                         opline->op1_type = IS_TMP_VAR;
    4056          34 :                         opline->op1.var = loop_var->var_num;
    4057          34 :                         SET_UNUSED(opline->op2);
    4058       50951 :                 } else if (loop_var->opcode == ZEND_RETURN) {
    4059             :                         /* Stack separator */
    4060       45633 :                         break;
    4061        5318 :                 } else if (depth <= 1) {
    4062        2271 :                         return 1;
    4063        3047 :                 } else if (loop_var->opcode == ZEND_NOP) {
    4064             :                         /* Loop doesn't have freeable variable */
    4065        2451 :                         depth--;
    4066             :                 } else {
    4067             :                         zend_op *opline;
    4068             : 
    4069             :                         ZEND_ASSERT(loop_var->var_type & (IS_VAR|IS_TMP_VAR));
    4070         596 :                         opline = get_next_op(CG(active_op_array));
    4071         596 :                         opline->opcode = loop_var->opcode;
    4072         596 :                         opline->op1_type = loop_var->var_type;
    4073         596 :                         opline->op1.var = loop_var->var_num;
    4074         596 :                         SET_UNUSED(opline->op2);
    4075         596 :                         opline->op2.num = loop_var->u.live_range_offset;
    4076         596 :                         opline->extended_value = ZEND_FREE_ON_RETURN;
    4077         596 :                         depth--;
    4078             :             }
    4079             :         }
    4080       45651 :         return (depth == 0);
    4081             : }
    4082             : /* }}} */
    4083             : 
    4084       46372 : static int zend_handle_loops_and_finally(znode *return_value) /* {{{ */
    4085             : {
    4086       46372 :         return zend_handle_loops_and_finally_ex(zend_stack_count(&CG(loop_var_stack)) + 1, return_value);
    4087             : }
    4088             : /* }}} */
    4089             : 
    4090          10 : static int zend_has_finally_ex(zend_long depth) /* {{{ */
    4091             : {
    4092             :         zend_loop_var *base;
    4093          10 :         zend_loop_var *loop_var = zend_stack_top(&CG(loop_var_stack));
    4094             : 
    4095          10 :         if (!loop_var) {
    4096           0 :                 return 0;
    4097             :         }
    4098          10 :         base = zend_stack_base(&CG(loop_var_stack));
    4099          11 :         for (; loop_var >= base; loop_var--) {
    4100          11 :                 if (loop_var->opcode == ZEND_FAST_CALL) {
    4101           8 :                         return 1;
    4102           3 :                 } else if (loop_var->opcode == ZEND_DISCARD_EXCEPTION) {
    4103           2 :                 } else if (loop_var->opcode == ZEND_RETURN) {
    4104             :                         /* Stack separator */
    4105           2 :                         return 0;
    4106           0 :                 } else if (depth <= 1) {
    4107           0 :                         return 0;
    4108             :                 } else {
    4109           0 :                         depth--;
    4110             :             }
    4111             :         }
    4112           0 :         return 0;
    4113             : }
    4114             : /* }}} */
    4115             : 
    4116          10 : static int zend_has_finally(void) /* {{{ */
    4117             : {
    4118          10 :         return zend_has_finally_ex(zend_stack_count(&CG(loop_var_stack)) + 1);
    4119             : }
    4120             : /* }}} */
    4121             : 
    4122       46331 : void zend_compile_return(zend_ast *ast) /* {{{ */
    4123             : {
    4124       46331 :         zend_ast *expr_ast = ast->child[0];
    4125       46331 :         zend_bool is_generator = (CG(active_op_array)->fn_flags & ZEND_ACC_GENERATOR) != 0;
    4126       46331 :         zend_bool by_ref = (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;
    4127             : 
    4128             :         znode expr_node;
    4129             :         zend_op *opline;
    4130             : 
    4131       46331 :         if (is_generator) {
    4132             :                 /* For generators the by-ref flag refers to yields, not returns */
    4133          32 :                 by_ref = 0;
    4134             :         }
    4135             : 
    4136       46331 :         if (!expr_ast) {
    4137         523 :                 expr_node.op_type = IS_CONST;
    4138         523 :                 ZVAL_NULL(&expr_node.u.constant);
    4139       45870 :         } else if (by_ref && zend_is_variable(expr_ast) && !zend_is_call(expr_ast)) {
    4140          62 :                 zend_compile_var(&expr_node, expr_ast, BP_VAR_W);
    4141             :         } else {
    4142       45746 :                 zend_compile_expr(&expr_node, expr_ast);
    4143             :         }
    4144             : 
    4145       46408 :         if ((CG(active_op_array)->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK)
    4146          69 :          && (expr_node.op_type == IS_CV || (by_ref && expr_node.op_type == IS_VAR))
    4147          10 :          && zend_has_finally()) {
    4148             :                 /* Copy return value into temporary VAR to avoid modification in finally code */
    4149           8 :                 if (by_ref) {
    4150           4 :                         zend_emit_op(&expr_node, ZEND_MAKE_REF, &expr_node, NULL);
    4151             :                 } else {
    4152           4 :                         zend_emit_op_tmp(&expr_node, ZEND_QM_ASSIGN, &expr_node, NULL);
    4153             :                 }
    4154             :         }
    4155             : 
    4156             :         /* Generator return types are handled separately */
    4157       46329 :         if (!is_generator && CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
    4158          94 :                 zend_emit_return_type_check(
    4159          94 :                         expr_ast ? &expr_node : NULL, CG(active_op_array)->arg_info - 1, 0);
    4160             :         }
    4161             : 
    4162       46325 :         zend_handle_loops_and_finally((expr_node.op_type & (IS_TMP_VAR | IS_VAR)) ? &expr_node : NULL);
    4163             : 
    4164       46325 :         opline = zend_emit_op(NULL, by_ref ? ZEND_RETURN_BY_REF : ZEND_RETURN,
    4165             :                 &expr_node, NULL);
    4166             : 
    4167       46325 :         if (by_ref && expr_ast) {
    4168          82 :                 if (zend_is_call(expr_ast)) {
    4169           9 :                         opline->extended_value = ZEND_RETURNS_FUNCTION;
    4170          73 :                 } else if (!zend_is_variable(expr_ast)) {
    4171          11 :                         opline->extended_value = ZEND_RETURNS_VALUE;
    4172             :                 }
    4173             :         }
    4174       46325 : }
    4175             : /* }}} */
    4176             : 
    4177       41060 : void zend_compile_echo(zend_ast *ast) /* {{{ */
    4178             : {
    4179             :         zend_op *opline;
    4180       41060 :         zend_ast *expr_ast = ast->child[0];
    4181             : 
    4182             :         znode expr_node;
    4183       41060 :         zend_compile_expr(&expr_node, expr_ast);
    4184             : 
    4185       41060 :         opline = zend_emit_op(NULL, ZEND_ECHO, &expr_node, NULL);
    4186       41060 :         opline->extended_value = 0;
    4187       41060 : }
    4188             : /* }}} */
    4189             : 
    4190         443 : void zend_compile_throw(zend_ast *ast) /* {{{ */
    4191             : {
    4192         443 :         zend_ast *expr_ast = ast->child[0];
    4193             : 
    4194             :         znode expr_node;
    4195         443 :         zend_compile_expr(&expr_node, expr_ast);
    4196             : 
    4197         443 :         zend_emit_op(NULL, ZEND_THROW, &expr_node, NULL);
    4198         443 : }
    4199             : /* }}} */
    4200             : 
    4201        2276 : void zend_compile_break_continue(zend_ast *ast) /* {{{ */
    4202             : {
    4203        2276 :         zend_ast *depth_ast = ast->child[0];
    4204             : 
    4205             :         zend_op *opline;
    4206             :         int depth;
    4207             : 
    4208             :         ZEND_ASSERT(ast->kind == ZEND_AST_BREAK || ast->kind == ZEND_AST_CONTINUE);
    4209             : 
    4210        2276 :         if (depth_ast) {
    4211             :                 zval *depth_zv;
    4212          29 :                 if (depth_ast->kind != ZEND_AST_ZVAL) {
    4213           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "'%s' operator with non-constant operand "
    4214           1 :                                 "is no longer supported", ast->kind == ZEND_AST_BREAK ? "break" : "continue");
    4215             :                 }
    4216             : 
    4217          28 :                 depth_zv = zend_ast_get_zval(depth_ast);
    4218          28 :                 if (Z_TYPE_P(depth_zv) != IS_LONG || Z_LVAL_P(depth_zv) < 1) {
    4219           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "'%s' operator accepts only positive numbers",
    4220           1 :                                 ast->kind == ZEND_AST_BREAK ? "break" : "continue");
    4221             :                 }
    4222             : 
    4223          27 :                 depth = Z_LVAL_P(depth_zv);
    4224             :         } else {
    4225        2247 :                 depth = 1;
    4226             :         }
    4227             : 
    4228        2274 :         if (CG(context).current_brk_cont == -1) {
    4229           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "'%s' not in the 'loop' or 'switch' context",
    4230           2 :                         ast->kind == ZEND_AST_BREAK ? "break" : "continue");
    4231             :         } else {
    4232        2272 :                 if (!zend_handle_loops_and_finally_ex(depth, NULL)) {
    4233           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot '%s' %d level%s",
    4234           1 :                                 ast->kind == ZEND_AST_BREAK ? "break" : "continue",
    4235             :                                 depth, depth == 1 ? "" : "s");
    4236             :                 }
    4237             :         }
    4238        2271 :         opline = zend_emit_op(NULL, ast->kind == ZEND_AST_BREAK ? ZEND_BRK : ZEND_CONT, NULL, NULL);
    4239        2271 :         opline->op1.num = CG(context).current_brk_cont;
    4240        2271 :         opline->op2.num = depth;
    4241        2271 : }
    4242             : /* }}} */
    4243             : 
    4244          47 : void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline) /* {{{ */
    4245             : {
    4246             :         zend_label *dest;
    4247          47 :         int current, remove_oplines = opline->op1.num;
    4248             :         zval *label;
    4249          47 :         uint32_t opnum = opline - op_array->opcodes;
    4250             : 
    4251          47 :         label = CT_CONSTANT_EX(op_array, opline->op2.constant);
    4252          93 :         if (CG(context).labels == NULL ||
    4253          46 :             (dest = zend_hash_find_ptr(CG(context).labels, Z_STR_P(label))) == NULL
    4254             :         ) {
    4255           1 :                 CG(in_compilation) = 1;
    4256           1 :                 CG(active_op_array) = op_array;
    4257           1 :                 CG(zend_lineno) = opline->lineno;
    4258           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "'goto' to undefined label '%s'", Z_STRVAL_P(label));
    4259             :         }
    4260             : 
    4261             :         zval_dtor(label);
    4262          46 :         ZVAL_NULL(label);
    4263             : 
    4264          46 :         current = opline->extended_value;
    4265          56 :         for (; current != dest->brk_cont; current = CG(context).brk_cont_array[current].parent) {
    4266          14 :                 if (current == -1) {
    4267           4 :                         CG(in_compilation) = 1;
    4268           4 :                         CG(active_op_array) = op_array;
    4269           4 :                         CG(zend_lineno) = opline->lineno;
    4270           4 :                         zend_error_noreturn(E_COMPILE_ERROR, "'goto' into loop or switch statement is disallowed");
    4271             :                 }
    4272          10 :                 if (CG(context).brk_cont_array[current].start >= 0) {
    4273           6 :                         remove_oplines--;
    4274             :                 }
    4275             :         }
    4276             : 
    4277          69 :         for (current = 0; current < op_array->last_try_catch; ++current) {
    4278          35 :                 zend_try_catch_element *elem = &op_array->try_catch_array[current];
    4279          35 :                 if (elem->try_op > opnum) {
    4280           8 :                         break;
    4281             :                 }
    4282          64 :                 if (elem->finally_op && opnum < elem->finally_op - 1
    4283          37 :                         && (dest->opline_num > elem->finally_end || dest->opline_num < elem->try_op)
    4284             :                 ) {
    4285           7 :                         remove_oplines--;
    4286             :                 }
    4287             :         }
    4288             : 
    4289          42 :         opline->opcode = ZEND_JMP;
    4290          42 :         opline->op1.opline_num = dest->opline_num;
    4291          42 :         opline->extended_value = 0;
    4292          42 :         SET_UNUSED(opline->op1);
    4293          42 :         SET_UNUSED(opline->op2);
    4294          42 :         SET_UNUSED(opline->result);
    4295             : 
    4296             :         ZEND_ASSERT(remove_oplines >= 0);
    4297          99 :         while (remove_oplines--) {
    4298          15 :                 opline--;
    4299          15 :                 MAKE_NOP(opline);
    4300          15 :                 ZEND_VM_SET_OPCODE_HANDLER(opline);
    4301             :         }
    4302          42 : }
    4303             : /* }}} */
    4304             : 
    4305          47 : void zend_compile_goto(zend_ast *ast) /* {{{ */
    4306             : {
    4307          47 :         zend_ast *label_ast = ast->child[0];
    4308             :         znode label_node;
    4309             :         zend_op *opline;
    4310          47 :         uint32_t opnum_start = get_next_op_number(CG(active_op_array));
    4311             : 
    4312          47 :         zend_compile_expr(&label_node, label_ast);
    4313             : 
    4314             :         /* Label resolution and unwinding adjustments happen in pass two. */
    4315          47 :         zend_handle_loops_and_finally(NULL);
    4316          47 :         opline = zend_emit_op(NULL, ZEND_GOTO, NULL, &label_node);
    4317          47 :         opline->op1.num = get_next_op_number(CG(active_op_array)) - opnum_start - 1;
    4318          47 :         opline->extended_value = CG(context).current_brk_cont;
    4319          47 : }
    4320             : /* }}} */
    4321             : 
    4322          48 : void zend_compile_label(zend_ast *ast) /* {{{ */
    4323             : {
    4324          96 :         zend_string *label = zend_ast_get_str(ast->child[0]);
    4325             :         zend_label dest;
    4326             : 
    4327          48 :         if (!CG(context).labels) {
    4328          32 :                 ALLOC_HASHTABLE(CG(context).labels);
    4329          32 :                 zend_hash_init(CG(context).labels, 8, NULL, label_ptr_dtor, 0);
    4330             :         }
    4331             : 
    4332          48 :         dest.brk_cont = CG(context).current_brk_cont;
    4333          48 :         dest.opline_num = get_next_op_number(CG(active_op_array));
    4334             : 
    4335          96 :         if (!zend_hash_add_mem(CG(context).labels, label, &dest, sizeof(zend_label))) {
    4336           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Label '%s' already defined", ZSTR_VAL(label));
    4337             :         }
    4338          47 : }
    4339             : /* }}} */
    4340             : 
    4341        2072 : void zend_compile_while(zend_ast *ast) /* {{{ */
    4342             : {
    4343        2072 :         zend_ast *cond_ast = ast->child[0];
    4344        2072 :         zend_ast *stmt_ast = ast->child[1];
    4345             :         znode cond_node;
    4346             :         uint32_t opnum_start, opnum_jmp, opnum_cond;
    4347             : 
    4348        2072 :         opnum_jmp = zend_emit_jump(0);
    4349             : 
    4350        2072 :         zend_begin_loop(ZEND_NOP, NULL);
    4351             : 
    4352        2072 :         opnum_start = get_next_op_number(CG(active_op_array));
    4353        2072 :         zend_compile_stmt(stmt_ast);
    4354             : 
    4355        2071 :         opnum_cond = get_next_op_number(CG(active_op_array));
    4356        2071 :         zend_update_jump_target(opnum_jmp, opnum_cond);
    4357        2071 :         zend_compile_expr(&cond_node, cond_ast);
    4358             : 
    4359        2071 :         zend_emit_cond_jump(ZEND_JMPNZ, &cond_node, opnum_start);
    4360             : 
    4361        2071 :         zend_end_loop(opnum_cond, NULL);
    4362        2071 : }
    4363             : /* }}} */
    4364             : 
    4365         311 : void zend_compile_do_while(zend_ast *ast) /* {{{ */
    4366             : {
    4367         311 :         zend_ast *stmt_ast = ast->child[0];
    4368         311 :         zend_ast *cond_ast = ast->child[1];
    4369             : 
    4370             :         znode cond_node;
    4371             :         uint32_t opnum_start, opnum_cond;
    4372             : 
    4373         311 :         zend_begin_loop(ZEND_NOP, NULL);
    4374             : 
    4375         311 :         opnum_start = get_next_op_number(CG(active_op_array));
    4376         311 :         zend_compile_stmt(stmt_ast);
    4377             : 
    4378         311 :         opnum_cond = get_next_op_number(CG(active_op_array));
    4379         311 :         zend_compile_expr(&cond_node, cond_ast);
    4380             : 
    4381         311 :         zend_emit_cond_jump(ZEND_JMPNZ, &cond_node, opnum_start);
    4382             : 
    4383         311 :         zend_end_loop(opnum_cond, NULL);
    4384         311 : }
    4385             : /* }}} */
    4386             : 
    4387        6783 : void zend_compile_expr_list(znode *result, zend_ast *ast) /* {{{ */
    4388             : {
    4389             :         zend_ast_list *list;
    4390             :         uint32_t i;
    4391             : 
    4392        6783 :         result->op_type = IS_CONST;
    4393        6783 :         ZVAL_TRUE(&result->u.constant);
    4394             : 
    4395        6783 :         if (!ast) {
    4396           7 :                 return;
    4397             :         }
    4398             : 
    4399        6776 :         list = zend_ast_get_list(ast);
    4400       13563 :         for (i = 0; i < list->children; ++i) {
    4401        6787 :                 zend_ast *expr_ast = list->child[i];
    4402             : 
    4403        6787 :                 zend_do_free(result);
    4404        6787 :                 zend_compile_expr(result, expr_ast);
    4405             :         }
    4406             : }
    4407             : /* }}} */
    4408             : 
    4409        2261 : void zend_compile_for(zend_ast *ast) /* {{{ */
    4410             : {
    4411        2261 :         zend_ast *init_ast = ast->child[0];
    4412        2261 :         zend_ast *cond_ast = ast->child[1];
    4413        2261 :         zend_ast *loop_ast = ast->child[2];
    4414        2261 :         zend_ast *stmt_ast = ast->child[3];
    4415             : 
    4416             :         znode result;
    4417             :         uint32_t opnum_start, opnum_jmp, opnum_loop;
    4418             : 
    4419        2261 :         zend_compile_expr_list(&result, init_ast);
    4420        2261 :         zend_do_free(&result);
    4421             : 
    4422        2261 :         opnum_jmp = zend_emit_jump(0);
    4423             : 
    4424        2261 :         zend_begin_loop(ZEND_NOP, NULL);
    4425             : 
    4426        2261 :         opnum_start = get_next_op_number(CG(active_op_array));
    4427        2261 :         zend_compile_stmt(stmt_ast);
    4428             : 
    4429        2261 :         opnum_loop = get_next_op_number(CG(active_op_array));
    4430        2261 :         zend_compile_expr_list(&result, loop_ast);
    4431        2261 :         zend_do_free(&result);
    4432             : 
    4433        2261 :         zend_update_jump_target_to_next(opnum_jmp);
    4434        2261 :         zend_compile_expr_list(&result, cond_ast);
    4435        2261 :         zend_do_extended_info();
    4436             : 
    4437        2261 :         zend_emit_cond_jump(ZEND_JMPNZ, &result, opnum_start);
    4438             : 
    4439        2261 :         zend_end_loop(opnum_loop, NULL);
    4440        2261 : }
    4441             : /* }}} */
    4442             : 
    4443       11992 : void zend_compile_foreach(zend_ast *ast) /* {{{ */
    4444             : {
    4445       11992 :         zend_ast *expr_ast = ast->child[0];
    4446       11992 :         zend_ast *value_ast = ast->child[1];
    4447       11992 :         zend_ast *key_ast = ast->child[2];
    4448       11992 :         zend_ast *stmt_ast = ast->child[3];
    4449       11992 :         zend_bool by_ref = value_ast->kind == ZEND_AST_REF;
    4450       21862 :         zend_bool is_variable = zend_is_variable(expr_ast) && !zend_is_call(expr_ast)
    4451       21862 :                 && zend_can_write_to_variable(expr_ast);
    4452             : 
    4453             :         znode expr_node, reset_node, value_node, key_node;
    4454             :         zend_op *opline;
    4455             :         uint32_t opnum_reset, opnum_fetch;
    4456             : 
    4457       11992 :         if (key_ast) {
    4458        5222 :                 if (key_ast->kind == ZEND_AST_REF) {
    4459           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Key element cannot be a reference");
    4460             :                 }
    4461        5220 :                 if (key_ast->kind == ZEND_AST_ARRAY) {
    4462           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use list as key element");
    4463             :                 }
    4464             :         }
    4465             : 
    4466       11989 :         if (by_ref) {
    4467         112 :                 value_ast = value_ast->child[0];
    4468             :         }
    4469             : 
    4470       12093 :         if (by_ref && is_variable) {
    4471         104 :                 zend_compile_var(&expr_node, expr_ast, BP_VAR_W);
    4472             :         } else {
    4473       11885 :                 zend_compile_expr(&expr_node, expr_ast);
    4474             :         }
    4475             : 
    4476       11986 :         if (by_ref) {
    4477         112 :                 zend_separate_if_call_and_write(&expr_node, expr_ast, BP_VAR_W);
    4478             :         }
    4479             : 
    4480       11986 :         opnum_reset = get_next_op_number(CG(active_op_array));
    4481       11986 :         opline = zend_emit_op(&reset_node, by_ref ? ZEND_FE_RESET_RW : ZEND_FE_RESET_R, &expr_node, NULL);
    4482             : 
    4483       11986 :         zend_begin_loop(ZEND_FE_FREE, &reset_node);
    4484             : 
    4485       11986 :         opnum_fetch = get_next_op_number(CG(active_op_array));
    4486       11986 :         opline = zend_emit_op(NULL, by_ref ? ZEND_FE_FETCH_RW : ZEND_FE_FETCH_R, &reset_node, NULL);
    4487             : 
    4488       11986 :         if (is_this_fetch(value_ast)) {
    4489           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
    4490       35916 :         } else if (value_ast->kind == ZEND_AST_VAR &&
    4491       11966 :             zend_try_compile_cv(&value_node, value_ast) == SUCCESS) {
    4492       11966 :                 SET_NODE(opline->op2, &value_node);
    4493             :         } else {
    4494          18 :                 opline->op2_type = IS_VAR;
    4495          18 :                 opline->op2.var = get_temporary_variable(CG(active_op_array));
    4496          18 :                 GET_NODE(&value_node, opline->op2);
    4497          18 :                 if (by_ref) {
    4498           0 :                         zend_emit_assign_ref_znode(value_ast, &value_node);
    4499             :                 } else {
    4500          18 :                         zend_emit_assign_znode(value_ast, &value_node);
    4501             :                 }
    4502             :         }
    4503             : 
    4504       11982 :         if (key_ast) {
    4505        5218 :                 opline = &CG(active_op_array)->opcodes[opnum_fetch];
    4506        5218 :                 zend_make_tmp_result(&key_node, opline);
    4507        5218 :                 zend_emit_assign_znode(key_ast, &key_node);
    4508             :         }
    4509             : 
    4510       11981 :         zend_compile_stmt(stmt_ast);
    4511             : 
    4512       11981 :         zend_emit_jump(opnum_fetch);
    4513             : 
    4514       11981 :         opline = &CG(active_op_array)->opcodes[opnum_reset];
    4515       11981 :         opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    4516             : 
    4517       11981 :         opline = &CG(active_op_array)->opcodes[opnum_fetch];
    4518       11981 :         opline->extended_value = get_next_op_number(CG(active_op_array));
    4519             : 
    4520       11981 :         zend_end_loop(opnum_fetch, &reset_node);
    4521             : 
    4522       11981 :         opline = zend_emit_op(NULL, ZEND_FE_FREE, &reset_node, NULL);
    4523       11981 : }
    4524             : /* }}} */
    4525             : 
    4526       80248 : void zend_compile_if(zend_ast *ast) /* {{{ */
    4527             : {
    4528       80248 :         zend_ast_list *list = zend_ast_get_list(ast);
    4529             :         uint32_t i;
    4530       80248 :         uint32_t *jmp_opnums = NULL;
    4531             : 
    4532       80248 :         if (list->children > 1) {
    4533       22454 :                 jmp_opnums = safe_emalloc(sizeof(uint32_t), list->children - 1, 0);
    4534             :         }
    4535             : 
    4536      183782 :         for (i = 0; i < list->children; ++i) {
    4537      103534 :                 zend_ast *elem_ast = list->child[i];
    4538      103534 :                 zend_ast *cond_ast = elem_ast->child[0];
    4539      103534 :                 zend_ast *stmt_ast = elem_ast->child[1];
    4540             : 
    4541             :                 znode cond_node;
    4542             :                 uint32_t opnum_jmpz;
    4543      103534 :                 if (cond_ast) {
    4544       82212 :                         zend_compile_expr(&cond_node, cond_ast);
    4545       82212 :                         opnum_jmpz = zend_emit_cond_jump(ZEND_JMPZ, &cond_node, 0);
    4546             :                 }
    4547             : 
    4548      103534 :                 zend_compile_stmt(stmt_ast);
    4549             : 
    4550      103534 :                 if (i != list->children - 1) {
    4551       23286 :                         jmp_opnums[i] = zend_emit_jump(0);
    4552             :                 }
    4553             : 
    4554      103534 :                 if (cond_ast) {
    4555       82212 :                         zend_update_jump_target_to_next(opnum_jmpz);
    4556             :                 }
    4557             :         }
    4558             : 
    4559       80248 :         if (list->children > 1) {
    4560       45740 :                 for (i = 0; i < list->children - 1; ++i) {
    4561       23286 :                         zend_update_jump_target_to_next(jmp_opnums[i]);
    4562             :                 }
    4563       22454 :                 efree(jmp_opnums);
    4564             :         }
    4565       80248 : }
    4566             : /* }}} */
    4567             : 
    4568         498 : void zend_compile_switch(zend_ast *ast) /* {{{ */
    4569             : {
    4570         498 :         zend_ast *expr_ast = ast->child[0];
    4571         996 :         zend_ast_list *cases = zend_ast_get_list(ast->child[1]);
    4572             : 
    4573             :         uint32_t i;
    4574         498 :         zend_bool has_default_case = 0;
    4575             : 
    4576             :         znode expr_node, case_node;
    4577             :         zend_op *opline;
    4578             :         uint32_t *jmpnz_opnums, opnum_default_jmp;
    4579             : 
    4580         498 :         zend_compile_expr(&expr_node, expr_ast);
    4581             : 
    4582         498 :         zend_begin_loop(ZEND_FREE, &expr_node);
    4583             : 
    4584         498 :         case_node.op_type = IS_TMP_VAR;
    4585         498 :         case_node.u.op.var = get_temporary_variable(CG(active_op_array));
    4586             : 
    4587         498 :         jmpnz_opnums = safe_emalloc(sizeof(uint32_t), cases->children, 0);
    4588        2463 :         for (i = 0; i < cases->children; ++i) {
    4589        1966 :                 zend_ast *case_ast = cases->child[i];
    4590        1966 :                 zend_ast *cond_ast = case_ast->child[0];
    4591             :                 znode cond_node;
    4592             : 
    4593        1966 :                 if (!cond_ast) {
    4594         291 :                         if (has_default_case) {
    4595           1 :                                 CG(zend_lineno) = case_ast->lineno;
    4596           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    4597             :                                         "Switch statements may only contain one default clause");
    4598             :                         }
    4599         290 :                         has_default_case = 1;
    4600         290 :                         continue;
    4601             :                 }
    4602             : 
    4603        1675 :                 zend_compile_expr(&cond_node, cond_ast);
    4604             : 
    4605        1689 :                 if (expr_node.op_type == IS_CONST
    4606        1675 :                         && Z_TYPE(expr_node.u.constant) == IS_FALSE) {
    4607           0 :                         jmpnz_opnums[i] = zend_emit_cond_jump(ZEND_JMPZ, &cond_node, 0);
    4608        1695 :                 } else if (expr_node.op_type == IS_CONST
    4609        1675 :                         && Z_TYPE(expr_node.u.constant) == IS_TRUE) {
    4610           6 :                         jmpnz_opnums[i] = zend_emit_cond_jump(ZEND_JMPNZ, &cond_node, 0);
    4611             :                 } else {                    
    4612        1669 :                         opline = zend_emit_op(NULL, ZEND_CASE, &expr_node, &cond_node);
    4613        1669 :                         SET_NODE(opline->result, &case_node);
    4614        1669 :                         if (opline->op1_type == IS_CONST) {
    4615           8 :                                 zval_copy_ctor(CT_CONSTANT(opline->op1));
    4616             :                         }
    4617             : 
    4618        1669 :                         jmpnz_opnums[i] = zend_emit_cond_jump(ZEND_JMPNZ, &case_node, 0);
    4619             :                 }
    4620             :         }
    4621             : 
    4622         497 :         opnum_default_jmp = zend_emit_jump(0);
    4623             : 
    4624        2459 :         for (i = 0; i < cases->children; ++i) {
    4625        1962 :                 zend_ast *case_ast = cases->child[i];
    4626        1962 :                 zend_ast *cond_ast = case_ast->child[0];
    4627        1962 :                 zend_ast *stmt_ast = case_ast->child[1];
    4628             : 
    4629        1962 :                 if (cond_ast) {
    4630        1673 :                         zend_update_jump_target_to_next(jmpnz_opnums[i]);
    4631             :                 } else {
    4632         289 :                         zend_update_jump_target_to_next(opnum_default_jmp);
    4633             :                 }
    4634             : 
    4635        1962 :                 zend_compile_stmt(stmt_ast);
    4636             :         }
    4637             : 
    4638         497 :         if (!has_default_case) {
    4639         208 :                 zend_update_jump_target_to_next(opnum_default_jmp);
    4640             :         }
    4641             : 
    4642         497 :         zend_end_loop(get_next_op_number(CG(active_op_array)), &expr_node);
    4643             : 
    4644         497 :         if (expr_node.op_type & (IS_VAR|IS_TMP_VAR)) {
    4645             :                 /* don't use emit_op() to prevent automatic live-range construction */
    4646         118 :                 opline = get_next_op(CG(active_op_array));
    4647         118 :                 opline->opcode = ZEND_FREE;
    4648         118 :                 SET_NODE(opline->op1, &expr_node);
    4649         118 :                 SET_UNUSED(opline->op2);
    4650         379 :         } else if (expr_node.op_type == IS_CONST) {
    4651             :                 zval_dtor(&expr_node.u.constant);
    4652             :         }
    4653             : 
    4654         497 :         efree(jmpnz_opnums);
    4655         497 : }
    4656             : /* }}} */
    4657             : 
    4658        2938 : void zend_compile_try(zend_ast *ast) /* {{{ */
    4659             : {
    4660        2938 :         zend_ast *try_ast = ast->child[0];
    4661        5876 :         zend_ast_list *catches = zend_ast_get_list(ast->child[1]);
    4662        2938 :         zend_ast *finally_ast = ast->child[2];
    4663             : 
    4664             :         uint32_t i, j;
    4665             :         zend_op *opline;
    4666             :         uint32_t try_catch_offset;
    4667        2938 :         uint32_t *jmp_opnums = safe_emalloc(sizeof(uint32_t), catches->children, 0);
    4668        2938 :         uint32_t orig_fast_call_var = CG(context).fast_call_var;
    4669        2938 :         uint32_t orig_try_catch_offset = CG(context).try_catch_offset;
    4670             : 
    4671        2938 :         if (catches->children == 0 && !finally_ast) {
    4672           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use try without catch or finally");
    4673             :         }
    4674             : 
    4675             :         /* label: try { } must not be equal to try { label: } */
    4676        2937 :         if (CG(context).labels) {
    4677             :                 zend_label *label;
    4678          18 :                 ZEND_HASH_REVERSE_FOREACH_PTR(CG(context).labels, label) {
    4679           6 :                         if (label->opline_num == get_next_op_number(CG(active_op_array))) {
    4680           2 :                                 zend_emit_op(NULL, ZEND_NOP, NULL, NULL);
    4681             :                         }
    4682           6 :                         break;
    4683             :                 } ZEND_HASH_FOREACH_END();
    4684             :         }
    4685             : 
    4686        2937 :         try_catch_offset = zend_add_try_element(get_next_op_number(CG(active_op_array)));
    4687             : 
    4688        2937 :         if (finally_ast) {
    4689             :                 zend_loop_var fast_call;
    4690         160 :                 if (!(CG(active_op_array)->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK)) {
    4691         108 :                         CG(active_op_array)->fn_flags |= ZEND_ACC_HAS_FINALLY_BLOCK;
    4692             :                 }
    4693         160 :                 CG(context).fast_call_var = get_temporary_variable(CG(active_op_array));
    4694             : 
    4695             :                 /* Push FAST_CALL on unwind stack */
    4696         160 :                 fast_call.opcode = ZEND_FAST_CALL;
    4697         160 :                 fast_call.var_type = IS_TMP_VAR;
    4698         160 :                 fast_call.var_num = CG(context).fast_call_var;
    4699         160 :                 fast_call.u.try_catch_offset = try_catch_offset;
    4700         160 :                 zend_stack_push(&CG(loop_var_stack), &fast_call);
    4701             :         }
    4702             : 
    4703        2937 :         CG(context).try_catch_offset = try_catch_offset;
    4704             : 
    4705        2937 :         zend_compile_stmt(try_ast);
    4706             : 
    4707        2936 :         if (catches->children != 0) {
    4708        2823 :                 jmp_opnums[0] = zend_emit_jump(0);
    4709             :         }
    4710             : 
    4711        5789 :         for (i = 0; i < catches->children; ++i) {
    4712        2855 :                 zend_ast *catch_ast = catches->child[i];
    4713        5710 :                 zend_ast_list *classes = zend_ast_get_list(catch_ast->child[0]);
    4714        2855 :                 zend_ast *var_ast = catch_ast->child[1];
    4715        2855 :                 zend_ast *stmt_ast = catch_ast->child[2];
    4716        2855 :                 zval *var_name = zend_ast_get_zval(var_ast);
    4717        2855 :                 zend_bool is_last_catch = (i + 1 == catches->children);
    4718             : 
    4719        2855 :                 uint32_t *jmp_multicatch = safe_emalloc(sizeof(uint32_t), classes->children - 1, 0);
    4720             :                 uint32_t opnum_catch;
    4721             : 
    4722        2855 :                 CG(zend_lineno) = catch_ast->lineno;
    4723             : 
    4724        5721 :                 for (j = 0; j < classes->children; j++) {
    4725             : 
    4726        2868 :                         zend_ast *class_ast = classes->child[j];
    4727        2868 :                         zend_bool is_last_class = (j + 1 == classes->children);
    4728             : 
    4729        2868 :                         if (!zend_is_const_default_class_ref(class_ast)) {
    4730           0 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Bad class name in the catch statement");
    4731             :                         }
    4732             : 
    4733        2868 :                         opnum_catch = get_next_op_number(CG(active_op_array));
    4734        2868 :                         if (i == 0 && j == 0) {
    4735        2823 :                                 CG(active_op_array)->try_catch_array[try_catch_offset].catch_op = opnum_catch;
    4736             :                         }
    4737             : 
    4738        2868 :                         opline = get_next_op(CG(active_op_array));
    4739        2868 :                         opline->opcode = ZEND_CATCH;
    4740        2868 :                         opline->op1_type = IS_CONST;
    4741        2868 :                         opline->op1.constant = zend_add_class_name_literal(CG(active_op_array),
    4742             :                                         zend_resolve_class_name_ast(class_ast));
    4743             : 
    4744        2868 :                         if (zend_string_equals_literal(Z_STR_P(var_name), "this")) {
    4745           2 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
    4746             :                         }
    4747             : 
    4748        2866 :                         opline->op2_type = IS_CV;
    4749        5732 :                         opline->op2.var = lookup_cv(CG(active_op_array), zend_string_copy(Z_STR_P(var_name)));
    4750             : 
    4751        2866 :                         opline->result.num = is_last_catch && is_last_class;
    4752             : 
    4753        2866 :                         if (!is_last_class) {
    4754          13 :                                 jmp_multicatch[j] = zend_emit_jump(0);
    4755          13 :                                 opline->extended_value = get_next_op_number(CG(active_op_array));
    4756             :                         }
    4757             :                 }
    4758             : 
    4759        2866 :                 for (j = 0; j < classes->children - 1; j++) {
    4760          13 :                         zend_update_jump_target_to_next(jmp_multicatch[j]);
    4761             :                 }
    4762             : 
    4763        2853 :                 efree(jmp_multicatch);
    4764             : 
    4765        2853 :                 zend_compile_stmt(stmt_ast);
    4766             : 
    4767        2853 :                 if (!is_last_catch) {
    4768          32 :                         jmp_opnums[i + 1] = zend_emit_jump(0);
    4769             :                 }
    4770             : 
    4771        2853 :                 opline = &CG(active_op_array)->opcodes[opnum_catch];
    4772        2853 :                 if (!is_last_catch) {
    4773          32 :                         opline->extended_value = get_next_op_number(CG(active_op_array));
    4774             :                 }
    4775             :         }
    4776             : 
    4777        5787 :         for (i = 0; i < catches->children; ++i) {
    4778        2853 :                 zend_update_jump_target_to_next(jmp_opnums[i]);
    4779             :         }
    4780             : 
    4781        2934 :         if (finally_ast) {
    4782             :                 zend_loop_var discard_exception;
    4783         159 :                 uint32_t opnum_jmp = get_next_op_number(CG(active_op_array)) + 1;
    4784             :                 
    4785             :                 /* Pop FAST_CALL from unwind stack */
    4786         159 :                 zend_stack_del_top(&CG(loop_var_stack));
    4787             : 
    4788             :                 /* Push DISCARD_EXCEPTION on unwind stack */
    4789         159 :                 discard_exception.opcode = ZEND_DISCARD_EXCEPTION;
    4790         159 :                 discard_exception.var_type = IS_TMP_VAR;
    4791         159 :                 discard_exception.var_num = CG(context).fast_call_var;
    4792         159 :                 zend_stack_push(&CG(loop_var_stack), &discard_exception);
    4793             : 
    4794         159 :                 CG(zend_lineno) = finally_ast->lineno;
    4795             : 
    4796         159 :                 opline = zend_emit_op(NULL, ZEND_FAST_CALL, NULL, NULL);
    4797         159 :                 opline->op1.num = try_catch_offset;
    4798         159 :                 opline->result_type = IS_TMP_VAR;
    4799         159 :                 opline->result.var = CG(context).fast_call_var;
    4800             : 
    4801         159 :                 zend_emit_op(NULL, ZEND_JMP, NULL, NULL);
    4802             : 
    4803         159 :                 CG(context).in_finally++;
    4804         159 :                 zend_compile_stmt(finally_ast);
    4805         159 :                 CG(context).in_finally--;
    4806             : 
    4807         159 :                 CG(active_op_array)->try_catch_array[try_catch_offset].finally_op = opnum_jmp + 1;
    4808         318 :                 CG(active_op_array)->try_catch_array[try_catch_offset].finally_end
    4809         159 :                         = get_next_op_number(CG(active_op_array));
    4810             : 
    4811         159 :                 opline = zend_emit_op(NULL, ZEND_FAST_RET, NULL, NULL);
    4812         159 :                 opline->op1_type = IS_TMP_VAR;
    4813         159 :                 opline->op1.var = CG(context).fast_call_var;
    4814         159 :                 opline->op2.num = orig_try_catch_offset;
    4815             : 
    4816         159 :                 zend_update_jump_target_to_next(opnum_jmp);
    4817             : 
    4818         159 :                 CG(context).fast_call_var = orig_fast_call_var;
    4819             : 
    4820             :                 /* Pop DISCARD_EXCEPTION from unwind stack */
    4821         159 :                 zend_stack_del_top(&CG(loop_var_stack));
    4822             :         }
    4823             : 
    4824        2934 :         CG(context).try_catch_offset = orig_try_catch_offset;
    4825             : 
    4826        2934 :         efree(jmp_opnums);
    4827        2934 : }
    4828             : /* }}} */
    4829             : 
    4830             : /* Encoding declarations must already be handled during parsing */
    4831          70 : void zend_handle_encoding_declaration(zend_ast *ast) /* {{{ */
    4832             : {
    4833          70 :         zend_ast_list *declares = zend_ast_get_list(ast);
    4834             :         uint32_t i;
    4835         137 :         for (i = 0; i < declares->children; ++i) {
    4836          71 :                 zend_ast *declare_ast = declares->child[i];
    4837          71 :                 zend_ast *name_ast = declare_ast->child[0];
    4838          71 :                 zend_ast *value_ast = declare_ast->child[1];
    4839          71 :                 zend_string *name = zend_ast_get_str(name_ast);
    4840             : 
    4841          71 :                 if (zend_string_equals_literal_ci(name, "encoding")) {
    4842          33 :                         if (value_ast->kind != ZEND_AST_ZVAL) {
    4843           4 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Encoding must be a literal");
    4844             :                         }
    4845             : 
    4846          29 :                         if (CG(multibyte)) {
    4847          28 :                                 zend_string *encoding_name = zval_get_string(zend_ast_get_zval(value_ast));
    4848             : 
    4849             :                                 const zend_encoding *new_encoding, *old_encoding;
    4850             :                                 zend_encoding_filter old_input_filter;
    4851             : 
    4852          28 :                                 CG(encoding_declared) = 1;
    4853             : 
    4854          28 :                                 new_encoding = zend_multibyte_fetch_encoding(ZSTR_VAL(encoding_name));
    4855          28 :                                 if (!new_encoding) {
    4856           8 :                                         zend_error(E_COMPILE_WARNING, "Unsupported encoding [%s]", ZSTR_VAL(encoding_name));
    4857             :                                 } else {
    4858          20 :                                         old_input_filter = LANG_SCNG(input_filter);
    4859          20 :                                         old_encoding = LANG_SCNG(script_encoding);
    4860          20 :                                         zend_multibyte_set_filter(new_encoding);
    4861             : 
    4862             :                                         /* need to re-scan if input filter changed */
    4863          20 :                                         if (old_input_filter != LANG_SCNG(input_filter) ||
    4864             :                                                  (old_input_filter && new_encoding != old_encoding)) {
    4865          14 :                                                 zend_multibyte_yyinput_again(old_input_filter, old_encoding);
    4866             :                                         }
    4867             :                                 }
    4868             : 
    4869             :                                 zend_string_release(encoding_name);
    4870             :                         } else {
    4871           1 :                                 zend_error(E_COMPILE_WARNING, "declare(encoding=...) ignored because "
    4872             :                                         "Zend multibyte feature is turned off by settings");
    4873             :                         }
    4874             :                 }
    4875             :         }
    4876          66 : }
    4877             : /* }}} */
    4878             : 
    4879          46 : static int zend_declare_is_first_statement(zend_ast *ast) /* {{{ */
    4880             : {
    4881          46 :         uint32_t i = 0;
    4882          92 :         zend_ast_list *file_ast = zend_ast_get_list(CG(ast));
    4883             : 
    4884             :         /* Check to see if this declare is preceeded only by declare statements */
    4885          98 :         while (i < file_ast->children) {
    4886          52 :                 if (file_ast->child[i] == ast) {
    4887          38 :                         return SUCCESS;
    4888          14 :                 } else if (file_ast->child[i] == NULL) {
    4889             :                         /* Empty statements are not allowed prior to a declare */
    4890           1 :                         return FAILURE;
    4891          13 :                 } else if (file_ast->child[i]->kind != ZEND_AST_DECLARE) {
    4892             :                         /* declares can only be preceeded by other declares */
    4893           7 :                         return FAILURE;
    4894             :                 }
    4895           6 :                 i++;
    4896             :         }
    4897           0 :         return FAILURE;
    4898             : }
    4899             : /* }}} */
    4900             : 
    4901          53 : void zend_compile_declare(zend_ast *ast) /* {{{ */
    4902             : {
    4903         106 :         zend_ast_list *declares = zend_ast_get_list(ast->child[0]);
    4904          53 :         zend_ast *stmt_ast = ast->child[1];
    4905          53 :         zend_declarables orig_declarables = FC(declarables);
    4906             :         uint32_t i;
    4907             : 
    4908          97 :         for (i = 0; i < declares->children; ++i) {
    4909          53 :                 zend_ast *declare_ast = declares->child[i];
    4910          53 :                 zend_ast *name_ast = declare_ast->child[0];
    4911          53 :                 zend_ast *value_ast = declare_ast->child[1];
    4912             : 
    4913          53 :                 zend_string *name = zend_ast_get_str(name_ast);
    4914          60 :                 if (zend_string_equals_literal_ci(name, "ticks")) {
    4915             :                         zval value_zv;
    4916           7 :                         zend_const_expr_to_zval(&value_zv, value_ast);
    4917           7 :                         FC(declarables).ticks = zval_get_long(&value_zv);
    4918             :                         zval_dtor(&value_zv);
    4919          61 :                 } else if (zend_string_equals_literal_ci(name, "encoding")) {
    4920             : 
    4921          19 :                         if (FAILURE == zend_declare_is_first_statement(ast)) {
    4922           4 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Encoding declaration pragma must be "
    4923             :                                         "the very first statement in the script");
    4924             :                         }
    4925          49 :                 } else if (zend_string_equals_literal_ci(name, "strict_types")) {
    4926             :                         zval value_zv;
    4927             : 
    4928          27 :                         if (FAILURE == zend_declare_is_first_statement(ast)) {
    4929           4 :                                 zend_error_noreturn(E_COMPILE_ERROR, "strict_types declaration must be "
    4930             :                                         "the very first statement in the script");
    4931             :                         }
    4932             : 
    4933          23 :                         if (ast->child[1] != NULL) {
    4934           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "strict_types declaration must not "
    4935             :                                         "use block mode");
    4936             :                         }
    4937             : 
    4938          22 :                         zend_const_expr_to_zval(&value_zv, value_ast);
    4939             : 
    4940          22 :                         if (Z_TYPE(value_zv) != IS_LONG || (Z_LVAL(value_zv) != 0 && Z_LVAL(value_zv) != 1)) {
    4941           0 :                                 zend_error_noreturn(E_COMPILE_ERROR, "strict_types declaration must have 0 or 1 as its value");
    4942             :                         }
    4943             : 
    4944          22 :                         if (Z_LVAL(value_zv) == 1) {
    4945          18 :                                 CG(active_op_array)->fn_flags |= ZEND_ACC_STRICT_TYPES;
    4946             :                         }
    4947             : 
    4948             :                 } else {
    4949           0 :                         zend_error(E_COMPILE_WARNING, "Unsupported declare '%s'", ZSTR_VAL(name));
    4950             :                 }
    4951             :         }
    4952             : 
    4953          44 :         if (stmt_ast) {
    4954           7 :                 zend_compile_stmt(stmt_ast);
    4955             : 
    4956           6 :                 FC(declarables) = orig_declarables;
    4957             :         }
    4958          43 : }
    4959             : /* }}} */
    4960             : 
    4961      162411 : void zend_compile_stmt_list(zend_ast *ast) /* {{{ */
    4962             : {
    4963      162411 :         zend_ast_list *list = zend_ast_get_list(ast);
    4964             :         uint32_t i;
    4965      483942 :         for (i = 0; i < list->children; ++i) {
    4966      321628 :                 zend_compile_stmt(list->child[i]);
    4967             :         }
    4968      162314 : }
    4969             : /* }}} */
    4970             : 
    4971    90183215 : ZEND_API void zend_set_function_arg_flags(zend_function *func) /* {{{ */
    4972             : {
    4973             :         uint32_t i, n;
    4974             : 
    4975    90183215 :         func->common.arg_flags[0] = 0;
    4976    90183215 :         func->common.arg_flags[1] = 0;
    4977    90183215 :         func->common.arg_flags[2] = 0;
    4978    90183215 :         if (func->common.arg_info) {
    4979    87931646 :                 n = MIN(func->common.num_args, MAX_ARG_FLAG_NUM);
    4980    87931646 :                 i = 0;
    4981   315011452 :                 while (i < n) {
    4982   139148160 :                         ZEND_SET_ARG_FLAG(func, i + 1, func->common.arg_info[i].pass_by_reference);
    4983   139148160 :                         i++;
    4984             :                 }
    4985    87931646 :                 if (UNEXPECTED(func->common.fn_flags & ZEND_ACC_VARIADIC && func->common.arg_info[i].pass_by_reference)) {
    4986      211084 :                         uint32_t pass_by_reference = func->common.arg_info[i].pass_by_reference;
    4987     2626832 :                         while (i < MAX_ARG_FLAG_NUM) {
    4988     2204664 :                                 ZEND_SET_ARG_FLAG(func, i + 1, pass_by_reference);
    4989     2204664 :                                 i++;
    4990             :                         }
    4991             :                 }
    4992             :         }
    4993    90183215 : }
    4994             : /* }}} */
    4995             : 
    4996         766 : static void zend_compile_typename(zend_ast *ast, zend_arg_info *arg_info) /* {{{ */
    4997             : {
    4998         766 :         if (ast->kind == ZEND_AST_TYPE) {
    4999         301 :                 arg_info->type_hint = ast->attr;
    5000             :         } else {
    5001         465 :                 zend_string *class_name = zend_ast_get_str(ast);
    5002         465 :                 zend_uchar type = zend_lookup_builtin_type_by_name(class_name);
    5003             : 
    5004         465 :                 if (type != 0) {
    5005         207 :                         if ((ast->attr & ZEND_NAME_NOT_FQ) != ZEND_NAME_NOT_FQ) {
    5006           2 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    5007             :                                         "Scalar type declaration '%s' must be unqualified",
    5008           2 :                                         ZSTR_VAL(zend_string_tolower(class_name)));
    5009             :                         }
    5010         205 :                         arg_info->type_hint = type;
    5011             :                 } else {
    5012         258 :                         uint32_t fetch_type = zend_get_class_fetch_type_ast(ast);
    5013         258 :                         if (fetch_type == ZEND_FETCH_CLASS_DEFAULT) {
    5014         230 :                                 class_name = zend_resolve_class_name_ast(ast);
    5015         229 :                                 zend_assert_valid_class_name(class_name);
    5016             :                         } else {
    5017          28 :                                 zend_ensure_valid_class_fetch_type(fetch_type);
    5018             :                                 zend_string_addref(class_name);
    5019             :                         }
    5020             : 
    5021         254 :                         arg_info->type_hint = IS_OBJECT;
    5022         254 :                         arg_info->class_name = class_name;
    5023             :                 }
    5024             :         }
    5025         760 : }
    5026             : /* }}} */
    5027             : 
    5028       39904 : void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
    5029             : {
    5030       39904 :         zend_ast_list *list = zend_ast_get_list(ast);
    5031             :         uint32_t i;
    5032       39904 :         zend_op_array *op_array = CG(active_op_array);
    5033             :         zend_arg_info *arg_infos;
    5034             :         
    5035       39904 :         if (return_type_ast) {
    5036             :                 /* Use op_array->arg_info[-1] for return type */
    5037         159 :                 arg_infos = safe_emalloc(sizeof(zend_arg_info), list->children + 1, 0);
    5038         159 :                 arg_infos->name = NULL;
    5039         159 :                 arg_infos->pass_by_reference = (op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;
    5040         159 :                 arg_infos->is_variadic = 0;
    5041         159 :                 arg_infos->type_hint = 0;
    5042         159 :                 arg_infos->allow_null = 0;
    5043         159 :                 arg_infos->class_name = NULL;
    5044             : 
    5045         159 :                 if (return_type_ast->attr & ZEND_TYPE_NULLABLE) {
    5046          13 :                         arg_infos->allow_null = 1;
    5047          13 :                         return_type_ast->attr &= ~ZEND_TYPE_NULLABLE;
    5048             :                 }
    5049             : 
    5050         159 :                 zend_compile_typename(return_type_ast, arg_infos);
    5051             : 
    5052         157 :                 if (arg_infos->type_hint == IS_VOID && arg_infos->allow_null) {
    5053           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Void type cannot be nullable");
    5054             :                 }
    5055             : 
    5056         156 :                 arg_infos++;
    5057         156 :                 op_array->fn_flags |= ZEND_ACC_HAS_RETURN_TYPE;
    5058             :         } else {
    5059       39745 :                 if (list->children == 0) {
    5060       10133 :                         return;
    5061             :                 }
    5062       29612 :                 arg_infos = safe_emalloc(sizeof(zend_arg_info), list->children, 0);
    5063             :         }
    5064             : 
    5065      119026 :         for (i = 0; i < list->children; ++i) {
    5066       89278 :                 zend_ast *param_ast = list->child[i];
    5067       89278 :                 zend_ast *type_ast = param_ast->child[0];
    5068       89278 :                 zend_ast *var_ast = param_ast->child[1];
    5069       89278 :                 zend_ast *default_ast = param_ast->child[2];
    5070       89278 :                 zend_string *name = zend_ast_get_str(var_ast);
    5071       89278 :                 zend_bool is_ref = (param_ast->attr & ZEND_PARAM_REF) != 0;
    5072       89278 :                 zend_bool is_variadic = (param_ast->attr & ZEND_PARAM_VARIADIC) != 0;
    5073             : 
    5074             :                 znode var_node, default_node;
    5075             :                 zend_uchar opcode;
    5076             :                 zend_op *opline;
    5077             :                 zend_arg_info *arg_info;
    5078             : 
    5079       89278 :                 if (zend_is_auto_global(name)) {
    5080           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign auto-global variable %s",
    5081             :                                 ZSTR_VAL(name));
    5082             :                 }
    5083             : 
    5084       89278 :                 var_node.op_type = IS_CV;
    5085       89278 :                 var_node.u.op.var = lookup_cv(CG(active_op_array), zend_string_copy(name));
    5086             : 
    5087       89278 :                 if (EX_VAR_TO_NUM(var_node.u.op.var) != i) {
    5088           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Redefinition of parameter $%s",
    5089             :                                 ZSTR_VAL(name));
    5090       89276 :                 } else if (zend_string_equals_literal(name, "this")) {
    5091           4 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as parameter");
    5092             :                 }
    5093             : 
    5094       89272 :                 if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
    5095           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Only the last parameter can be variadic");
    5096             :                 }
    5097             : 
    5098       89271 :                 if (is_variadic) {
    5099          42 :                         opcode = ZEND_RECV_VARIADIC;
    5100          42 :                         default_node.op_type = IS_UNUSED;
    5101          42 :                         op_array->fn_flags |= ZEND_ACC_VARIADIC;
    5102             : 
    5103          42 :                         if (default_ast) {
    5104           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    5105             :                                         "Variadic parameter cannot have a default value");
    5106             :                         }
    5107       89229 :                 } else if (default_ast) {
    5108             :                         /* we cannot substitute constants here or it will break ReflectionParameter::getDefaultValueConstantName() and ReflectionParameter::isDefaultValueConstant() */
    5109       16528 :                         uint32_t cops = CG(compiler_options);
    5110       16528 :                         CG(compiler_options) |= ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION | ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION;
    5111       16528 :                         opcode = ZEND_RECV_INIT;
    5112       16528 :                         default_node.op_type = IS_CONST;
    5113       16528 :                         zend_const_expr_to_zval(&default_node.u.constant, default_ast);
    5114       16526 :                         CG(compiler_options) = cops;
    5115             :                 } else {
    5116       72701 :                         opcode = ZEND_RECV;
    5117       72701 :                         default_node.op_type = IS_UNUSED;
    5118       72701 :                         op_array->required_num_args = i + 1;
    5119             :                 }
    5120             : 
    5121       89268 :                 opline = zend_emit_op(NULL, opcode, NULL, &default_node);
    5122       89268 :                 SET_NODE(opline->result, &var_node);
    5123       89268 :                 opline->op1.num = i + 1;
    5124             : 
    5125       89268 :                 arg_info = &arg_infos[i];
    5126       89268 :                 arg_info->name = zend_string_copy(name);
    5127       89268 :                 arg_info->pass_by_reference = is_ref;
    5128       89268 :                 arg_info->is_variadic = is_variadic;
    5129       89268 :                 arg_info->type_hint = 0;
    5130       89268 :                 arg_info->allow_null = 1;
    5131       89268 :                 arg_info->class_name = NULL;
    5132             : 
    5133       89268 :                 if (type_ast) {
    5134         715 :                         zend_bool has_null_default = default_ast
    5135             :                                 && (Z_TYPE(default_node.u.constant) == IS_NULL
    5136             :                                         || (Z_TYPE(default_node.u.constant) == IS_CONSTANT
    5137         617 :                                                 && strcasecmp(Z_STRVAL(default_node.u.constant), "NULL") == 0));
    5138         607 :                         zend_bool is_explicitly_nullable = (type_ast->attr & ZEND_TYPE_NULLABLE) == ZEND_TYPE_NULLABLE;
    5139             : 
    5140         607 :                         op_array->fn_flags |= ZEND_ACC_HAS_TYPE_HINTS;
    5141         607 :                         arg_info->allow_null = has_null_default || is_explicitly_nullable;
    5142             : 
    5143         607 :                         zend_compile_typename(type_ast, arg_info);
    5144             : 
    5145         603 :                         if (arg_info->type_hint == IS_VOID) {
    5146           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "void cannot be used as a parameter type");
    5147             :                         }
    5148             : 
    5149         602 :                         if (type_ast->kind == ZEND_AST_TYPE) {
    5150         278 :                                 if (arg_info->type_hint == IS_ARRAY) {
    5151         280 :                                         if (default_ast && !has_null_default
    5152             :                                                 && Z_TYPE(default_node.u.constant) != IS_ARRAY
    5153           3 :                                                 && !Z_CONSTANT(default_node.u.constant)
    5154             :                                         ) {
    5155           1 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    5156             :                                                         "with array type can only be an array or NULL");
    5157             :                                         }
    5158          12 :                                 } else if (arg_info->type_hint == IS_CALLABLE && default_ast) {
    5159           1 :                                         if (!has_null_default && !Z_CONSTANT(default_node.u.constant)) {
    5160           0 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    5161             :                                                         "with callable type can only be NULL");
    5162             :                                         }
    5163             :                                 }
    5164             :                         } else {
    5165         324 :                                 if (default_ast && !has_null_default && !Z_CONSTANT(default_node.u.constant)) {
    5166           9 :                                         if (arg_info->class_name) {
    5167           1 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    5168             :                                                         "with a class type can only be NULL");
    5169           8 :                                         } else switch (arg_info->type_hint) {
    5170             :                                                 case IS_DOUBLE:
    5171           6 :                                                         if (Z_TYPE(default_node.u.constant) != IS_DOUBLE && Z_TYPE(default_node.u.constant) != IS_LONG) {
    5172           1 :                                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    5173             :                                                                         "with a float type can only be float, integer, or NULL");
    5174             :                                                         }
    5175           2 :                                                         break;
    5176             :                                                 
    5177             :                                                 case IS_ITERABLE:
    5178           2 :                                                         if (Z_TYPE(default_node.u.constant) != IS_ARRAY) {
    5179           1 :                                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    5180             :                                                                         "with iterable type can only be an array or NULL");
    5181             :                                                         }
    5182           1 :                                                         break;
    5183             :                                                         
    5184             :                                                 default:
    5185           9 :                                                         if (!ZEND_SAME_FAKE_TYPE(arg_info->type_hint, Z_TYPE(default_node.u.constant))) {
    5186           2 :                                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    5187             :                                                                         "with a %s type can only be %s or NULL",
    5188           2 :                                                                         zend_get_type_by_const(arg_info->type_hint), zend_get_type_by_const(arg_info->type_hint));
    5189             :                                                         }
    5190             :                                                         break;
    5191             :                                         }
    5192             :                                 }
    5193             :                         }
    5194             : 
    5195             :                         /* Allocate cache slot to speed-up run-time class resolution */
    5196         597 :                         if (opline->opcode == ZEND_RECV_INIT) {
    5197          65 :                                 if (arg_info->class_name) {
    5198          20 :                                         zend_alloc_cache_slot(opline->op2.constant);
    5199             :                                 } else {
    5200          45 :                                         Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = -1;
    5201             :                                 }
    5202             :                         } else {
    5203         532 :                                 if (arg_info->class_name) {
    5204         167 :                                         opline->op2.num = op_array->cache_size;
    5205         167 :                                         op_array->cache_size += sizeof(void*);
    5206             :                                 } else {
    5207         365 :                                         opline->op2.num = -1;
    5208             :                                 }
    5209             :                         }
    5210             :                 } else {
    5211       88661 :                         if (opline->opcode == ZEND_RECV_INIT) {
    5212       16456 :                                 Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = -1;
    5213             :                         } else {
    5214       72205 :                                 opline->op2.num = -1;
    5215             :                         }
    5216             :                 }       
    5217             :         }
    5218             : 
    5219             :         /* These are assigned at the end to avoid unitialized memory in case of an error */
    5220       29748 :         op_array->num_args = list->children;
    5221       29748 :         op_array->arg_info = arg_infos;
    5222             : 
    5223             :         /* Don't count the variadic argument */
    5224       29748 :         if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
    5225          40 :                 op_array->num_args--;
    5226             :         }
    5227       29748 :         zend_set_function_arg_flags((zend_function*)op_array);
    5228             : }
    5229             : /* }}} */
    5230             : 
    5231         188 : static void zend_compile_closure_binding(znode *closure, zend_ast *uses_ast) /* {{{ */
    5232             : {
    5233         188 :         zend_ast_list *list = zend_ast_get_list(uses_ast);
    5234             :         uint32_t i;
    5235             : 
    5236         385 :         for (i = 0; i < list->children; ++i) {
    5237         199 :                 zend_ast *var_name_ast = list->child[i];
    5238         199 :                 zend_string *var_name = zend_ast_get_str(var_name_ast);
    5239         199 :                 zend_bool by_ref = var_name_ast->attr;
    5240             :                 zend_op *opline;
    5241             : 
    5242         199 :                 if (zend_string_equals_literal(var_name, "this")) {
    5243           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as lexical variable");
    5244             :                 }
    5245             : 
    5246         198 :                 if (zend_is_auto_global(var_name)) {
    5247           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use auto-global as lexical variable");
    5248             :                 }
    5249             : 
    5250         197 :                 opline = zend_emit_op(NULL, ZEND_BIND_LEXICAL, closure, NULL);
    5251         197 :                 opline->op2_type = IS_CV;
    5252         197 :                 opline->op2.var = lookup_cv(CG(active_op_array), zend_string_copy(var_name));
    5253         197 :                 opline->extended_value = by_ref;
    5254             :         }
    5255         186 : }
    5256             : /* }}} */
    5257             : 
    5258         186 : void zend_compile_closure_uses(zend_ast *ast) /* {{{ */
    5259             : {
    5260         186 :         zend_op_array *op_array = CG(active_op_array);
    5261         186 :         zend_ast_list *list = zend_ast_get_list(ast);
    5262             :         uint32_t i;
    5263             : 
    5264         381 :         for (i = 0; i < list->children; ++i) {
    5265         197 :                 zend_ast *var_ast = list->child[i];
    5266         197 :                 zend_string *var_name = zend_ast_get_str(var_ast);
    5267         197 :                 zend_bool by_ref = var_ast->attr;
    5268             :                 zval zv;
    5269         197 :                 ZVAL_NULL(&zv);
    5270             : 
    5271         208 :                 if (op_array->static_variables
    5272         208 :                                 && zend_hash_exists(op_array->static_variables, var_name)) {
    5273           1 :                         zend_error_noreturn(E_COMPILE_ERROR,
    5274             :                                 "Cannot use variable $%s twice", ZSTR_VAL(var_name));
    5275             :                 }
    5276             : 
    5277             :                 {
    5278             :                         int i;
    5279         382 :                         for (i = 0; i < op_array->last_var; i++) {
    5280         374 :                                 if (zend_string_equals(op_array->vars[i], var_name)) {
    5281           1 :                                         zend_error_noreturn(E_COMPILE_ERROR,
    5282             :                                                 "Cannot use lexical variable $%s as a parameter name", ZSTR_VAL(var_name));
    5283             :                                 }
    5284             :                         }
    5285             :                 }
    5286             : 
    5287         195 :                 zend_compile_static_var_common(var_ast, &zv, by_ref);
    5288             :         }
    5289         184 : }
    5290             : /* }}} */
    5291             : 
    5292       19103 : void zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_bool has_body) /* {{{ */
    5293             : {
    5294       19103 :         zend_class_entry *ce = CG(active_class_entry);
    5295       19103 :         zend_bool in_interface = (ce->ce_flags & ZEND_ACC_INTERFACE) != 0;
    5296       19103 :         zend_bool in_trait = (ce->ce_flags & ZEND_ACC_TRAIT) != 0;
    5297       19103 :         zend_bool is_public = (op_array->fn_flags & ZEND_ACC_PUBLIC) != 0;
    5298       19103 :         zend_bool is_static = (op_array->fn_flags & ZEND_ACC_STATIC) != 0;
    5299             : 
    5300             :         zend_string *lcname;
    5301             : 
    5302       19103 :         if (in_interface) {
    5303         134 :                 if (!is_public || (op_array->fn_flags & (ZEND_ACC_FINAL|ZEND_ACC_ABSTRACT))) {
    5304           6 :                         zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface method "
    5305           3 :                                 "%s::%s() must be omitted", ZSTR_VAL(ce->name), ZSTR_VAL(name));
    5306             :                 }
    5307         131 :                 op_array->fn_flags |= ZEND_ACC_ABSTRACT;
    5308             :         }
    5309             : 
    5310       19100 :         if (op_array->fn_flags & ZEND_ACC_ABSTRACT) {
    5311         200 :                 if (op_array->fn_flags & ZEND_ACC_PRIVATE) {
    5312           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "%s function %s::%s() cannot be declared private",
    5313           1 :                                 in_interface ? "Interface" : "Abstract", ZSTR_VAL(ce->name), ZSTR_VAL(name));
    5314             :                 }
    5315             : 
    5316         199 :                 if (has_body) {
    5317           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "%s function %s::%s() cannot contain body",
    5318           1 :                                 in_interface ? "Interface" : "Abstract", ZSTR_VAL(ce->name), ZSTR_VAL(name));
    5319             :                 }
    5320             : 
    5321         198 :                 ce->ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
    5322       18900 :         } else if (!has_body) {
    5323           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "Non-abstract method %s::%s() must contain body",
    5324           1 :                         ZSTR_VAL(ce->name), ZSTR_VAL(name));
    5325             :         }
    5326             : 
    5327       19097 :         op_array->scope = ce;
    5328       19097 :         op_array->function_name = zend_string_copy(name);
    5329             : 
    5330       19097 :         lcname = zend_string_tolower(name);
    5331       19097 :         lcname = zend_new_interned_string(lcname);
    5332             : 
    5333       38194 :         if (zend_hash_add_ptr(&ce->function_table, lcname, op_array) == NULL) {
    5334           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s::%s()",
    5335           1 :                         ZSTR_VAL(ce->name), ZSTR_VAL(name));
    5336             :         }
    5337             : 
    5338       19096 :         if (in_interface) {
    5339         131 :                 if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
    5340           1 :                         if (!is_public || is_static) {
    5341           1 :                                 zend_error(E_WARNING, "The magic method __call() must have "
    5342             :                                         "public visibility and cannot be static");
    5343             :                         }
    5344         130 :                 } else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
    5345           1 :                         if (!is_public || !is_static) {
    5346           1 :                                 zend_error(E_WARNING, "The magic method __callStatic() must have "
    5347             :                                         "public visibility and be static");
    5348             :                         }
    5349         128 :                 } else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
    5350           0 :                         if (!is_public || is_static) {
    5351           0 :                                 zend_error(E_WARNING, "The magic method __get() must have "
    5352             :                                         "public visibility and cannot be static");
    5353             :                         }
    5354         128 :                 } else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
    5355           0 :                         if (!is_public || is_static) {
    5356           0 :                                 zend_error(E_WARNING, "The magic method __set() must have "
    5357             :                                         "public visibility and cannot be static");
    5358             :                         }
    5359         128 :                 } else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
    5360           0 :                         if (!is_public || is_static) {
    5361           0 :                                 zend_error(E_WARNING, "The magic method __unset() must have "
    5362             :                                         "public visibility and cannot be static");
    5363             :                         }
    5364         128 :                 } else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
    5365           0 :                         if (!is_public || is_static) {
    5366           0 :                                 zend_error(E_WARNING, "The magic method __isset() must have "
    5367             :                                         "public visibility and cannot be static");
    5368             :                         }
    5369         128 :                 } else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
    5370           0 :                         if (!is_public || is_static) {
    5371           0 :                                 zend_error(E_WARNING, "The magic method __toString() must have "
    5372             :                                         "public visibility and cannot be static");
    5373             :                         }
    5374         129 :                 } else if (zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) {
    5375           1 :                         if (!is_public || is_static) {
    5376           1 :                                 zend_error(E_WARNING, "The magic method __invoke() must have "
    5377             :                                         "public visibility and cannot be static");
    5378             :                         }
    5379         127 :                 } else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) {
    5380           0 :                         if (!is_public || is_static) {
    5381           0 :                                 zend_error(E_WARNING, "The magic method __debugInfo() must have "
    5382             :                                         "public visibility and cannot be static");
    5383             :                         }
    5384             :                 }
    5385             :         } else {
    5386       19029 :                 if (!in_trait && zend_string_equals_ci(lcname, ce->name)) {
    5387          63 :                         if (!ce->constructor) {
    5388          53 :                                 ce->constructor = (zend_function *) op_array;
    5389             :                         }
    5390       20861 :                 } else if (zend_string_equals_literal(lcname, ZEND_CONSTRUCTOR_FUNC_NAME)) {
    5391        1958 :                         ce->constructor = (zend_function *) op_array;
    5392       17122 :                 } else if (zend_string_equals_literal(lcname, ZEND_DESTRUCTOR_FUNC_NAME)) {
    5393         177 :                         ce->destructor = (zend_function *) op_array;
    5394       16797 :                 } else if (zend_string_equals_literal(lcname, ZEND_CLONE_FUNC_NAME)) {
    5395          29 :                         ce->clone = (zend_function *) op_array;
    5396       16815 :                 } else if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
    5397          76 :                         if (!is_public || is_static) {
    5398           2 :                                 zend_error(E_WARNING, "The magic method __call() must have "
    5399             :                                         "public visibility and cannot be static");
    5400             :                         }
    5401          76 :                         ce->__call = (zend_function *) op_array;
    5402       16695 :                 } else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
    5403          32 :                         if (!is_public || !is_static) {
    5404           1 :                                 zend_error(E_WARNING, "The magic method __callStatic() must have "
    5405             :                                         "public visibility and be static");
    5406             :                         }
    5407          32 :                         ce->__callstatic = (zend_function *) op_array;
    5408       16708 :                 } else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
    5409          77 :                         if (!is_public || is_static) {
    5410           0 :                                 zend_error(E_WARNING, "The magic method __get() must have "
    5411             :                                         "public visibility and cannot be static");
    5412             :                         }
    5413          77 :                         ce->__get = (zend_function *) op_array;
    5414          77 :                         ce->ce_flags |= ZEND_ACC_USE_GUARDS;
    5415       16617 :                 } else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
    5416          63 :                         if (!is_public || is_static) {
    5417           2 :                                 zend_error(E_WARNING, "The magic method __set() must have "
    5418             :                                         "public visibility and cannot be static");
    5419             :                         }
    5420          63 :                         ce->__set = (zend_function *) op_array;
    5421          63 :                         ce->ce_flags |= ZEND_ACC_USE_GUARDS;
    5422       16509 :                 } else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
    5423          18 :                         if (!is_public || is_static) {
    5424           3 :                                 zend_error(E_WARNING, "The magic method __unset() must have "
    5425             :                                         "public visibility and cannot be static");
    5426             :                         }
    5427          18 :                         ce->__unset = (zend_function *) op_array;
    5428          18 :                         ce->ce_flags |= ZEND_ACC_USE_GUARDS;
    5429       16493 :                 } else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
    5430          20 :                         if (!is_public || is_static) {
    5431           0 :                                 zend_error(E_WARNING, "The magic method __isset() must have "
    5432             :                                         "public visibility and cannot be static");
    5433             :                         }
    5434          20 :                         ce->__isset = (zend_function *) op_array;
    5435          20 :                         ce->ce_flags |= ZEND_ACC_USE_GUARDS;
    5436       17164 :                 } else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
    5437         711 :                         if (!is_public || is_static) {
    5438           1 :                                 zend_error(E_WARNING, "The magic method __toString() must have "
    5439             :                                         "public visibility and cannot be static");
    5440             :                         }
    5441         711 :                         ce->__tostring = (zend_function *) op_array;
    5442       15760 :                 } else if (zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) {
    5443          18 :                         if (!is_public || is_static) {
    5444           2 :                                 zend_error(E_WARNING, "The magic method __invoke() must have "
    5445             :                                         "public visibility and cannot be static");
    5446             :                         }
    5447       15738 :                 } else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) {
    5448          14 :                         if (!is_public || is_static) {
    5449           0 :                                 zend_error(E_WARNING, "The magic method __debugInfo() must have "
    5450             :                                         "public visibility and cannot be static");
    5451             :                         }
    5452          14 :                         ce->__debugInfo = (zend_function *) op_array;
    5453       15710 :                 } else if (!is_static) {
    5454        8009 :                         op_array->fn_flags |= ZEND_ACC_ALLOW_STATIC;
    5455             :                 }
    5456             :         }
    5457             : 
    5458             :         zend_string_release(lcname);
    5459       19096 : }
    5460             : /* }}} */
    5461             : 
    5462       20813 : static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_ast_decl *decl) /* {{{ */
    5463             : {
    5464       20813 :         zend_ast *params_ast = decl->child[0];
    5465             :         zend_string *unqualified_name, *name, *lcname, *key;
    5466             :         zend_op *opline;
    5467             : 
    5468       20813 :         unqualified_name = decl->name;
    5469       20813 :         op_array->function_name = name = zend_prefix_with_ns(unqualified_name);
    5470       20813 :         lcname = zend_string_tolower(name);
    5471             : 
    5472       20813 :         if (FC(imports_function)) {
    5473           5 :                 zend_string *import_name = zend_hash_find_ptr_lc(
    5474           5 :                         FC(imports_function), ZSTR_VAL(unqualified_name), ZSTR_LEN(unqualified_name));
    5475           5 :                 if (import_name && !zend_string_equals_ci(lcname, import_name)) {
    5476           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare function %s "
    5477             :                                 "because the name is already in use", ZSTR_VAL(name));
    5478             :                 }
    5479             :         }
    5480             : 
    5481       20888 :         if (zend_string_equals_literal(lcname, ZEND_AUTOLOAD_FUNC_NAME)
    5482          77 :                 && zend_ast_get_list(params_ast)->children != 1
    5483             :         ) {
    5484           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "%s() must take exactly 1 argument",
    5485             :                         ZEND_AUTOLOAD_FUNC_NAME);
    5486             :         }
    5487             : 
    5488       20810 :         key = zend_build_runtime_definition_key(lcname, decl->lex_pos);
    5489       20810 :         zend_hash_update_ptr(CG(function_table), key, op_array);
    5490             : 
    5491       20810 :         if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
    5492         581 :                 opline = zend_emit_op_tmp(result, ZEND_DECLARE_LAMBDA_FUNCTION, NULL, NULL);
    5493         581 :                 opline->op1_type = IS_CONST;
    5494         581 :                 LITERAL_STR(opline->op1, key);
    5495             :         } else {
    5496       20229 :                 opline = get_next_op(CG(active_op_array));
    5497       20229 :                 opline->opcode = ZEND_DECLARE_FUNCTION;
    5498       20229 :                 opline->op1_type = IS_CONST;
    5499       40458 :                 LITERAL_STR(opline->op1, zend_string_copy(lcname));
    5500             :                 /* RTD key is placed after lcname literal in op1 */
    5501       20229 :                 zend_add_literal_string(CG(active_op_array), &key);
    5502       20229 :                 SET_UNUSED(opline->op2);
    5503             :         }
    5504             : 
    5505             :         zend_string_release(lcname);
    5506       20810 : }
    5507             : /* }}} */
    5508             : 
    5509       39916 : void zend_compile_func_decl(znode *result, zend_ast *ast) /* {{{ */
    5510             : {
    5511       39916 :         zend_ast_decl *decl = (zend_ast_decl *) ast;
    5512       39916 :         zend_ast *params_ast = decl->child[0];
    5513       39916 :         zend_ast *uses_ast = decl->child[1];
    5514       39916 :         zend_ast *stmt_ast = decl->child[2];
    5515       39916 :         zend_ast *return_type_ast = decl->child[3];
    5516       39916 :         zend_bool is_method = decl->kind == ZEND_AST_METHOD;
    5517             : 
    5518       39916 :         zend_op_array *orig_op_array = CG(active_op_array);
    5519       39916 :         zend_op_array *op_array = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
    5520             :         zend_oparray_context orig_oparray_context;
    5521             : 
    5522       39916 :         init_op_array(op_array, ZEND_USER_FUNCTION, INITIAL_OP_ARRAY_SIZE);
    5523             : 
    5524       39916 :         op_array->fn_flags |= (orig_op_array->fn_flags & ZEND_ACC_STRICT_TYPES);
    5525       39916 :         op_array->fn_flags |= decl->flags;
    5526       39916 :         op_array->line_start = decl->start_lineno;
    5527       39916 :         op_array->line_end = decl->end_lineno;
    5528       39916 :         if (decl->doc_comment) {
    5529        4848 :                 op_array->doc_comment = zend_string_copy(decl->doc_comment);
    5530             :         }
    5531       39916 :         if (decl->kind == ZEND_AST_CLOSURE) {
    5532         581 :                 op_array->fn_flags |= ZEND_ACC_CLOSURE;
    5533             :         }
    5534             : 
    5535       39916 :         if (is_method) {
    5536       19103 :                 zend_bool has_body = stmt_ast != NULL;
    5537       19103 :                 zend_begin_method_decl(op_array, decl->name, has_body);
    5538             :         } else {
    5539       20813 :                 zend_begin_func_decl(result, op_array, decl);
    5540       20810 :                 if (uses_ast) {
    5541         188 :                         zend_compile_closure_binding(result, uses_ast);
    5542             :                 }
    5543             :         }
    5544             : 
    5545       39904 :         CG(active_op_array) = op_array;
    5546             : 
    5547       39904 :         zend_oparray_context_begin(&orig_oparray_context);
    5548             : 
    5549       39904 :         if (CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO) {
    5550           0 :                 zend_op *opline_ext = zend_emit_op(NULL, ZEND_EXT_NOP, NULL, NULL);
    5551           0 :                 opline_ext->lineno = decl->start_lineno;
    5552             :         }
    5553             : 
    5554             :         {
    5555             :                 /* Push a separator to the loop variable stack */
    5556             :                 zend_loop_var dummy_var;
    5557       39904 :                 dummy_var.opcode = ZEND_RETURN;
    5558             : 
    5559       39904 :                 zend_stack_push(&CG(loop_var_stack), (void *) &dummy_var);
    5560             :         }
    5561             : 
    5562       39904 :         zend_compile_params(params_ast, return_type_ast);
    5563       39881 :         if (CG(active_op_array)->fn_flags & ZEND_ACC_GENERATOR) {
    5564         205 :                 zend_mark_function_as_generator();
    5565         204 :                 zend_emit_op(NULL, ZEND_GENERATOR_CREATE, NULL, NULL);
    5566             :         }
    5567       39880 :         if (uses_ast) {
    5568         186 :                 zend_compile_closure_uses(uses_ast);
    5569             :         }
    5570       39878 :         zend_compile_stmt(stmt_ast);
    5571             : 
    5572       39850 :         if (is_method) {
    5573       38154 :                 zend_check_magic_method_implementation(
    5574       19077 :                         CG(active_class_entry), (zend_function *) op_array, E_COMPILE_ERROR);
    5575             :         }
    5576             : 
    5577             :         /* put the implicit return on the really last line */
    5578       39834 :         CG(zend_lineno) = decl->end_lineno;
    5579             : 
    5580       39834 :         zend_do_extended_info();
    5581       39834 :         zend_emit_final_return(0);
    5582             : 
    5583       39834 :         pass_two(CG(active_op_array));
    5584       39827 :         zend_oparray_context_end(&orig_oparray_context);
    5585             : 
    5586             :         /* Pop the loop variable stack separator */
    5587       39827 :         zend_stack_del_top(&CG(loop_var_stack));
    5588             : 
    5589       39827 :         CG(active_op_array) = orig_op_array;
    5590       39827 : }
    5591             : /* }}} */
    5592             : 
    5593        2670 : void zend_compile_prop_decl(zend_ast *ast) /* {{{ */
    5594             : {
    5595        2670 :         zend_ast_list *list = zend_ast_get_list(ast);
    5596        2670 :         uint32_t flags = list->attr;
    5597        2670 :         zend_class_entry *ce = CG(active_class_entry);
    5598        2670 :         uint32_t i, children = list->children;
    5599             : 
    5600        2670 :         if (ce->ce_flags & ZEND_ACC_INTERFACE) {
    5601           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Interfaces may not include member variables");
    5602             :         }
    5603             : 
    5604        2669 :         if (flags & ZEND_ACC_ABSTRACT) {
    5605           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Properties cannot be declared abstract");
    5606             :         }
    5607             : 
    5608        5381 :         for (i = 0; i < children; ++i) {
    5609        2716 :                 zend_ast *prop_ast = list->child[i];
    5610        2716 :                 zend_ast *name_ast = prop_ast->child[0];
    5611        2716 :                 zend_ast *value_ast = prop_ast->child[1];
    5612        2716 :                 zend_ast *doc_comment_ast = prop_ast->child[2];
    5613        2716 :                 zend_string *name = zend_ast_get_str(name_ast);
    5614        2716 :                 zend_string *doc_comment = NULL;
    5615             :                 zval value_zv;
    5616             : 
    5617             :                 /* Doc comment has been appended as last element in ZEND_AST_PROP_ELEM ast */
    5618        2716 :                 if (doc_comment_ast) {
    5619          55 :                         doc_comment = zend_string_copy(zend_ast_get_str(doc_comment_ast));
    5620             :                 }
    5621             : 
    5622        2716 :                 if (flags & ZEND_ACC_FINAL) {
    5623           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare property %s::$%s final, "
    5624             :                                 "the final modifier is allowed only for methods and classes",
    5625           1 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(name));
    5626             :                 }
    5627             : 
    5628        2715 :                 if (zend_hash_exists(&ce->properties_info, name)) {
    5629           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s::$%s",
    5630           1 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(name));
    5631             :                 }
    5632             : 
    5633        2714 :                 if (value_ast) {
    5634        1469 :                         zend_const_expr_to_zval(&value_zv, value_ast);
    5635             :                 } else {
    5636        1245 :                         ZVAL_NULL(&value_zv);
    5637             :                 }
    5638             : 
    5639        2713 :                 name = zend_new_interned_string_safe(name);
    5640        2713 :                 zend_declare_property_ex(ce, name, &value_zv, flags, doc_comment);
    5641             :         }
    5642        2665 : }
    5643             : /* }}} */
    5644             : 
    5645         371 : void zend_compile_class_const_decl(zend_ast *ast) /* {{{ */
    5646             : {
    5647         371 :         zend_ast_list *list = zend_ast_get_list(ast);
    5648         371 :         zend_class_entry *ce = CG(active_class_entry);
    5649             :         uint32_t i;
    5650             : 
    5651         371 :         if ((ce->ce_flags & ZEND_ACC_TRAIT) != 0) {
    5652           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Traits cannot have constants");
    5653             :                 return;
    5654             :         }
    5655             : 
    5656         735 :         for (i = 0; i < list->children; ++i) {
    5657         376 :                 zend_ast *const_ast = list->child[i];
    5658         376 :                 zend_ast *name_ast = const_ast->child[0];
    5659         376 :                 zend_ast *value_ast = const_ast->child[1];
    5660         376 :                 zend_ast *doc_comment_ast = const_ast->child[2];
    5661         376 :                 zend_string *name = zend_ast_get_str(name_ast);
    5662         384 :                 zend_string *doc_comment = doc_comment_ast ? zend_string_copy(zend_ast_get_str(doc_comment_ast)) : NULL;
    5663             :                 zval value_zv;
    5664             : 
    5665         376 :                 if (UNEXPECTED(ast->attr & (ZEND_ACC_STATIC|ZEND_ACC_ABSTRACT|ZEND_ACC_FINAL))) {
    5666           3 :                         if (ast->attr & ZEND_ACC_STATIC) {
    5667           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'static' as constant modifier");
    5668           2 :                         } else if (ast->attr & ZEND_ACC_ABSTRACT) {
    5669           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'abstract' as constant modifier");
    5670           1 :                         } else if (ast->attr & ZEND_ACC_FINAL) {
    5671           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'final' as constant modifier");
    5672             :                         }
    5673             :                 }
    5674             : 
    5675         373 :                 zend_const_expr_to_zval(&value_zv, value_ast);
    5676             : 
    5677         370 :                 name = zend_new_interned_string_safe(name);
    5678         370 :                 zend_declare_class_constant_ex(ce, name, &value_zv, ast->attr, doc_comment);
    5679             :         }
    5680             : }
    5681             : /* }}} */
    5682             : 
    5683          95 : static zend_trait_method_reference *zend_compile_method_ref(zend_ast *ast) /* {{{ */
    5684             : {
    5685          95 :         zend_ast *class_ast = ast->child[0];
    5686          95 :         zend_ast *method_ast = ast->child[1];
    5687             : 
    5688          95 :         zend_trait_method_reference *method_ref = emalloc(sizeof(zend_trait_method_reference));
    5689          95 :         method_ref->ce = NULL;
    5690          95 :         method_ref->method_name = zend_string_copy(zend_ast_get_str(method_ast));
    5691             : 
    5692          95 :         if (class_ast) {
    5693          53 :                 method_ref->class_name = zend_resolve_class_name_ast(class_ast);
    5694             :         } else {
    5695          42 :                 method_ref->class_name = NULL;
    5696             :         }
    5697             : 
    5698          95 :         return method_ref;
    5699             : }
    5700             : /* }}} */
    5701             : 
    5702          22 : static zend_string **zend_compile_name_list(zend_ast *ast) /* {{{ */
    5703             : {
    5704          22 :         zend_ast_list *list = zend_ast_get_list(ast);
    5705          22 :         zend_string **names = safe_emalloc(sizeof(zend_string *), list->children + 1, 0);
    5706             :         uint32_t i;
    5707             : 
    5708          45 :         for (i = 0; i < list->children; ++i) {
    5709          23 :                 zend_ast *name_ast = list->child[i];
    5710          23 :                 names[i] = zend_resolve_class_name_ast(name_ast);
    5711             :         }
    5712             : 
    5713          22 :         names[list->children] = NULL;
    5714             : 
    5715          22 :         return names;
    5716             : }
    5717             : /* }}} */
    5718             : 
    5719          22 : static void zend_compile_trait_precedence(zend_ast *ast) /* {{{ */
    5720             : {
    5721          22 :         zend_ast *method_ref_ast = ast->child[0];
    5722          22 :         zend_ast *insteadof_ast = ast->child[1];
    5723             : 
    5724          22 :         zend_trait_precedence *precedence = emalloc(sizeof(zend_trait_precedence));
    5725          22 :         precedence->trait_method = zend_compile_method_ref(method_ref_ast);
    5726          22 :         precedence->exclude_from_classes
    5727             :                 = (void *) zend_compile_name_list(insteadof_ast);
    5728             : 
    5729          22 :         zend_add_to_list(&CG(active_class_entry)->trait_precedences, precedence);
    5730          22 : }
    5731             : /* }}} */
    5732             : 
    5733          76 : static void zend_compile_trait_alias(zend_ast *ast) /* {{{ */
    5734             : {
    5735          76 :         zend_ast *method_ref_ast = ast->child[0];
    5736          76 :         zend_ast *alias_ast = ast->child[1];
    5737          76 :         uint32_t modifiers = ast->attr;
    5738             : 
    5739             :         zend_trait_alias *alias;
    5740             : 
    5741          76 :         if (modifiers == ZEND_ACC_STATIC) {
    5742           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'static' as method modifier");
    5743          75 :         } else if (modifiers == ZEND_ACC_ABSTRACT) {
    5744           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'abstract' as method modifier");
    5745          74 :         } else if (modifiers == ZEND_ACC_FINAL) {
    5746           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'final' as method modifier");
    5747             :         }
    5748             : 
    5749          73 :         alias = emalloc(sizeof(zend_trait_alias));
    5750          73 :         alias->trait_method = zend_compile_method_ref(method_ref_ast);
    5751          73 :         alias->modifiers = modifiers;
    5752             : 
    5753          73 :         if (alias_ast) {
    5754          62 :                 alias->alias = zend_string_copy(zend_ast_get_str(alias_ast));
    5755             :         } else {
    5756          11 :                 alias->alias = NULL;
    5757             :         }
    5758             : 
    5759          73 :         zend_add_to_list(&CG(active_class_entry)->trait_aliases, alias);
    5760          73 : }
    5761             : /* }}} */
    5762             : 
    5763         223 : void zend_compile_use_trait(zend_ast *ast) /* {{{ */
    5764             : {
    5765         446 :         zend_ast_list *traits = zend_ast_get_list(ast->child[0]);
    5766         289 :         zend_ast_list *adaptations = ast->child[1] ? zend_ast_get_list(ast->child[1]) : NULL;
    5767         223 :         zend_class_entry *ce = CG(active_class_entry);
    5768             :         zend_op *opline;
    5769             :         uint32_t i;
    5770             : 
    5771         488 :         for (i = 0; i < traits->children; ++i) {
    5772         266 :                 zend_ast *trait_ast = traits->child[i];
    5773         266 :                 zend_string *name = zend_ast_get_str(trait_ast);
    5774             : 
    5775         266 :                 if (ce->ce_flags & ZEND_ACC_INTERFACE) {
    5776           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use traits inside of interfaces. "
    5777           1 :                                 "%s is used in %s", ZSTR_VAL(name), ZSTR_VAL(ce->name));
    5778             :                 }
    5779             : 
    5780         265 :                 switch (zend_get_class_fetch_type(name)) {
    5781             :                         case ZEND_FETCH_CLASS_SELF:
    5782             :                         case ZEND_FETCH_CLASS_PARENT:
    5783             :                         case ZEND_FETCH_CLASS_STATIC:
    5784           0 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use '%s' as trait name "
    5785             :                                         "as it is reserved", ZSTR_VAL(name));
    5786             :                                 break;
    5787             :                 }
    5788             : 
    5789         265 :                 opline = get_next_op(CG(active_op_array));
    5790         265 :                 opline->opcode = ZEND_ADD_TRAIT;
    5791         265 :                 SET_NODE(opline->op1, &FC(implementing_class));
    5792         265 :                 opline->op2_type = IS_CONST;
    5793         265 :                 opline->op2.constant = zend_add_class_name_literal(CG(active_op_array),
    5794             :                         zend_resolve_class_name_ast(trait_ast));
    5795             : 
    5796         265 :                 ce->num_traits++;
    5797             :         }
    5798             : 
    5799         222 :         if (!adaptations) {
    5800         156 :                 return;
    5801             :         }
    5802             : 
    5803         161 :         for (i = 0; i < adaptations->children; ++i) {
    5804          98 :                 zend_ast *adaptation_ast = adaptations->child[i];
    5805          98 :                 switch (adaptation_ast->kind) {
    5806             :                         case ZEND_AST_TRAIT_PRECEDENCE:
    5807          22 :                                 zend_compile_trait_precedence(adaptation_ast);
    5808          22 :                                 break;
    5809             :                         case ZEND_AST_TRAIT_ALIAS:
    5810          76 :                                 zend_compile_trait_alias(adaptation_ast);
    5811             :                                 break;
    5812             :                         EMPTY_SWITCH_DEFAULT_CASE()
    5813             :                 }
    5814             :         }
    5815             : }
    5816             : /* }}} */
    5817             : 
    5818         378 : void zend_compile_implements(znode *class_node, zend_ast *ast) /* {{{ */
    5819             : {
    5820         378 :         zend_ast_list *list = zend_ast_get_list(ast);
    5821             :         uint32_t i;
    5822         794 :         for (i = 0; i < list->children; ++i) {
    5823         418 :                 zend_ast *class_ast = list->child[i];
    5824         418 :                 zend_string *name = zend_ast_get_str(class_ast);
    5825             : 
    5826             :                 zend_op *opline;
    5827             : 
    5828         418 :                 if (!zend_is_const_default_class_ref(class_ast)) {
    5829           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    5830             :                                 "Cannot use '%s' as interface name as it is reserved", ZSTR_VAL(name));
    5831             :                 }
    5832             : 
    5833         416 :                 opline = zend_emit_op(NULL, ZEND_ADD_INTERFACE, class_node, NULL);
    5834         416 :                 opline->op2_type = IS_CONST;
    5835         416 :                 opline->op2.constant = zend_add_class_name_literal(CG(active_op_array),
    5836             :                         zend_resolve_class_name_ast(class_ast));
    5837             : 
    5838         416 :                 CG(active_class_entry)->num_interfaces++;
    5839             :         }
    5840         376 : }
    5841             : /* }}} */
    5842             : 
    5843          29 : static zend_string *zend_generate_anon_class_name(unsigned char *lex_pos) /* {{{ */
    5844             : {
    5845             :         zend_string *result;
    5846             :         char char_pos_buf[32];
    5847          29 :         size_t char_pos_len = zend_sprintf(char_pos_buf, "%p", lex_pos);
    5848          29 :         zend_string *filename = CG(active_op_array)->filename;
    5849             : 
    5850             :         /* NULL, name length, filename length, last accepting char position length */
    5851          58 :         result = zend_string_alloc(sizeof("class@anonymous") + ZSTR_LEN(filename) + char_pos_len, 0);
    5852          29 :         sprintf(ZSTR_VAL(result), "class@anonymous%c%s%s", '\0', ZSTR_VAL(filename), char_pos_buf);
    5853          29 :         return zend_new_interned_string(result);
    5854             : }
    5855             : /* }}} */
    5856             : 
    5857        8125 : void zend_compile_class_decl(zend_ast *ast) /* {{{ */
    5858             : {
    5859        8125 :         zend_ast_decl *decl = (zend_ast_decl *) ast;
    5860        8125 :         zend_ast *extends_ast = decl->child[0];
    5861        8125 :         zend_ast *implements_ast = decl->child[1];
    5862        8125 :         zend_ast *stmt_ast = decl->child[2];
    5863             :         zend_string *name, *lcname;
    5864        8125 :         zend_class_entry *ce = zend_arena_alloc(&CG(arena), sizeof(zend_class_entry));
    5865             :         zend_op *opline;
    5866             :         znode declare_node, extends_node;
    5867             : 
    5868        8125 :         zend_class_entry *original_ce = CG(active_class_entry);
    5869        8125 :         znode original_implementing_class = FC(implementing_class);
    5870             : 
    5871        8125 :         if (EXPECTED((decl->flags & ZEND_ACC_ANON_CLASS) == 0)) {
    5872        8096 :                 zend_string *unqualified_name = decl->name;
    5873             : 
    5874        8096 :                 if (CG(active_class_entry)) {
    5875           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Class declarations may not be nested");
    5876             :                 }
    5877             : 
    5878        8095 :                 zend_assert_valid_class_name(unqualified_name);
    5879        8087 :                 name = zend_prefix_with_ns(unqualified_name);
    5880        8087 :                 name = zend_new_interned_string(name);
    5881        8087 :                 lcname = zend_string_tolower(name);
    5882             : 
    5883        8087 :                 if (FC(imports)) {
    5884          30 :                         zend_string *import_name = zend_hash_find_ptr_lc(
    5885          30 :                                 FC(imports), ZSTR_VAL(unqualified_name), ZSTR_LEN(unqualified_name));
    5886          30 :                         if (import_name && !zend_string_equals_ci(lcname, import_name)) {
    5887           2 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare class %s "
    5888             :                                                 "because the name is already in use", ZSTR_VAL(name));
    5889             :                         }
    5890             :                 }
    5891             :         } else {
    5892          29 :                 name = zend_generate_anon_class_name(decl->lex_pos);
    5893          29 :                 lcname = zend_string_tolower(name);
    5894             :         }
    5895        8114 :         lcname = zend_new_interned_string(lcname);
    5896             : 
    5897        8114 :         ce->type = ZEND_USER_CLASS;
    5898        8114 :         ce->name = name;
    5899        8114 :         zend_initialize_class_data(ce, 1);
    5900             : 
    5901        8114 :         ce->ce_flags |= decl->flags;
    5902        8114 :         ce->info.user.filename = zend_get_compiled_filename();
    5903        8114 :         ce->info.user.line_start = decl->start_lineno;
    5904        8114 :         ce->info.user.line_end = decl->end_lineno;
    5905             : 
    5906        8114 :         if (decl->doc_comment) {
    5907         146 :                 ce->info.user.doc_comment = zend_string_copy(decl->doc_comment);
    5908             :         }
    5909             : 
    5910        8114 :         if (UNEXPECTED((decl->flags & ZEND_ACC_ANON_CLASS))) {
    5911             :                 /* Serialization is not supported for anonymous classes */
    5912          29 :                 ce->serialize = zend_class_serialize_deny;
    5913          29 :                 ce->unserialize = zend_class_unserialize_deny;
    5914             :         }
    5915             : 
    5916        8114 :         if (extends_ast) {
    5917        2506 :                 if (!zend_is_const_default_class_ref(extends_ast)) {
    5918           2 :                         zend_string *extends_name = zend_ast_get_str(extends_ast);
    5919           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    5920             :                                 "Cannot use '%s' as class name as it is reserved", ZSTR_VAL(extends_name));
    5921             :                 }
    5922             : 
    5923        2504 :                 zend_compile_class_ref(&extends_node, extends_ast, 0);
    5924             :         }
    5925             : 
    5926        8112 :         opline = get_next_op(CG(active_op_array));
    5927        8112 :         zend_make_var_result(&declare_node, opline);
    5928             : 
    5929        8112 :         GET_NODE(&FC(implementing_class), opline->result);
    5930             : 
    5931        8112 :         opline->op1_type = IS_CONST;
    5932        8112 :         LITERAL_STR(opline->op1, lcname);
    5933             : 
    5934        8112 :         if (decl->flags & ZEND_ACC_ANON_CLASS) {
    5935          29 :                 if (extends_ast) {
    5936           3 :                         opline->opcode = ZEND_DECLARE_ANON_INHERITED_CLASS;
    5937           3 :                         SET_NODE(opline->op2, &extends_node);
    5938             :                 } else {
    5939          26 :                         opline->opcode = ZEND_DECLARE_ANON_CLASS;
    5940             :                 }
    5941             : 
    5942          29 :                 if (!zend_hash_exists(CG(class_table), lcname)) {
    5943          28 :                         zend_hash_add_ptr(CG(class_table), lcname, ce);
    5944             :                 } else {
    5945             :                         /* this anonymous class has been included */
    5946             :                         zval zv;
    5947           1 :                         ZVAL_PTR(&zv, ce);
    5948           1 :                         destroy_zend_class(&zv);
    5949           1 :                         return;
    5950             :                 }
    5951             :         } else {
    5952             :                 zend_string *key;
    5953             : 
    5954        8083 :                 if (extends_ast) {
    5955        2501 :                         opline->opcode = ZEND_DECLARE_INHERITED_CLASS;
    5956        2501 :                         SET_NODE(opline->op2, &extends_node);
    5957             :                 } else {
    5958        5582 :                         opline->opcode = ZEND_DECLARE_CLASS;
    5959        5582 :                         SET_UNUSED(opline->op2);
    5960             :                 }
    5961             : 
    5962        8083 :                 key = zend_build_runtime_definition_key(lcname, decl->lex_pos);
    5963             :                 /* RTD key is placed after lcname literal in op1 */
    5964        8083 :                 zend_add_literal_string(CG(active_op_array), &key);
    5965             : 
    5966        8083 :                 zend_hash_update_ptr(CG(class_table), key, ce);
    5967             :         }
    5968             : 
    5969        8111 :         CG(active_class_entry) = ce;
    5970             : 
    5971        8111 :         zend_compile_stmt(stmt_ast);
    5972             : 
    5973             :         /* Reset lineno for final opcodes and errors */
    5974        8048 :         CG(zend_lineno) = ast->lineno;
    5975             : 
    5976        8048 :         if (ce->num_traits == 0) {
    5977             :                 /* For traits this check is delayed until after trait binding */
    5978        7851 :                 zend_check_deprecated_constructor(ce);
    5979             :         }
    5980             : 
    5981        8048 :         if (ce->constructor) {
    5982        2003 :                 ce->constructor->common.fn_flags |= ZEND_ACC_CTOR;
    5983        2003 :                 if (ce->constructor->common.fn_flags & ZEND_ACC_STATIC) {
    5984           4 :                         zend_error_noreturn(E_COMPILE_ERROR, "Constructor %s::%s() cannot be static",
    5985           4 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(ce->constructor->common.function_name));
    5986             :                 }
    5987        2001 :                 if (ce->constructor->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
    5988           4 :                         zend_error_noreturn(E_COMPILE_ERROR,
    5989             :                                 "Constructor %s::%s() cannot declare a return type",
    5990           4 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(ce->constructor->common.function_name));
    5991             :                 }
    5992             :         }
    5993        8044 :         if (ce->destructor) {
    5994         176 :                 ce->destructor->common.fn_flags |= ZEND_ACC_DTOR;
    5995         176 :                 if (ce->destructor->common.fn_flags & ZEND_ACC_STATIC) {
    5996           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Destructor %s::%s() cannot be static",
    5997           2 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(ce->destructor->common.function_name));
    5998         175 :                 } else if (ce->destructor->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
    5999           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    6000             :                                 "Destructor %s::%s() cannot declare a return type",
    6001           2 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(ce->destructor->common.function_name));
    6002             :                 }
    6003             :         }
    6004        8042 :         if (ce->clone) {
    6005          28 :                 ce->clone->common.fn_flags |= ZEND_ACC_CLONE;
    6006          28 :                 if (ce->clone->common.fn_flags & ZEND_ACC_STATIC) {
    6007           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Clone method %s::%s() cannot be static",
    6008           2 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(ce->clone->common.function_name));
    6009          27 :                 } else if (ce->clone->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
    6010           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    6011             :                                 "%s::%s() cannot declare a return type",
    6012           2 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(ce->clone->common.function_name));
    6013             :                 }
    6014             :         }
    6015             : 
    6016             :         /* Check for traits and proceed like with interfaces.
    6017             :          * The only difference will be a combined handling of them in the end.
    6018             :          * Thus, we need another opcode here. */
    6019        8040 :         if (ce->num_traits > 0) {
    6020         197 :                 ce->traits = NULL;
    6021         197 :                 ce->num_traits = 0;
    6022         197 :                 ce->ce_flags |= ZEND_ACC_IMPLEMENT_TRAITS;
    6023             : 
    6024         197 :                 zend_emit_op(NULL, ZEND_BIND_TRAITS, &declare_node, NULL);
    6025             :         }
    6026             : 
    6027        8040 :         if (implements_ast) {
    6028         378 :                 zend_compile_implements(&declare_node, implements_ast);
    6029             :         }
    6030             : 
    6031        8038 :         if (!(ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))
    6032             :                 && (extends_ast || implements_ast)
    6033             :         ) {
    6034        2762 :                 zend_verify_abstract_class(ce);
    6035        2760 :                 if (implements_ast) {
    6036         327 :                         zend_emit_op(NULL, ZEND_VERIFY_ABSTRACT_CLASS, &declare_node, NULL);
    6037             :                 }
    6038             :         }
    6039             : 
    6040             :         /* Inherit interfaces; reset number to zero, we need it for above check and
    6041             :          * will restore it during actual implementation.
    6042             :          * The ZEND_ACC_IMPLEMENT_INTERFACES flag disables double call to
    6043             :          * zend_verify_abstract_class() */
    6044        8036 :         if (ce->num_interfaces > 0) {
    6045         376 :                 ce->interfaces = NULL;
    6046         376 :                 ce->num_interfaces = 0;
    6047         376 :                 ce->ce_flags |= ZEND_ACC_IMPLEMENT_INTERFACES;
    6048             :         }
    6049             : 
    6050        8036 :         FC(implementing_class) = original_implementing_class;
    6051        8036 :         CG(active_class_entry) = original_ce;
    6052             : }
    6053             : /* }}} */
    6054             : 
    6055         135 : static HashTable *zend_get_import_ht(uint32_t type) /* {{{ */
    6056             : {
    6057         135 :         switch (type) {
    6058             :                 case T_CLASS:
    6059          80 :                         if (!FC(imports)) {
    6060          55 :                                 FC(imports) = emalloc(sizeof(HashTable));
    6061          55 :                                 zend_hash_init(FC(imports), 8, NULL, str_dtor, 0);
    6062             :                         }
    6063          80 :                         return FC(imports);
    6064             :                 case T_FUNCTION:
    6065          29 :                         if (!FC(imports_function)) {
    6066          20 :                                 FC(imports_function) = emalloc(sizeof(HashTable));
    6067          20 :                                 zend_hash_init(FC(imports_function), 8, NULL, str_dtor, 0);
    6068             :                         }
    6069          29 :                         return FC(imports_function);
    6070             :                 case T_CONST:
    6071          26 :                         if (!FC(imports_const)) {
    6072          17 :                                 FC(imports_const) = emalloc(sizeof(HashTable));
    6073          17 :                                 zend_hash_init(FC(imports_const), 8, NULL, str_dtor, 0);
    6074             :                         }
    6075          26 :                         return FC(imports_const);
    6076             :                 EMPTY_SWITCH_DEFAULT_CASE()
    6077             :         }
    6078             : 
    6079           0 :         return NULL;
    6080             : }
    6081             : /* }}} */
    6082             : 
    6083           7 : static char *zend_get_use_type_str(uint32_t type) /* {{{ */
    6084             : {
    6085           7 :         switch (type) {
    6086             :                 case T_CLASS:
    6087           2 :                         return "";
    6088             :                 case T_FUNCTION:
    6089           3 :                         return " function";
    6090             :                 case T_CONST:
    6091           2 :                         return " const";
    6092             :                 EMPTY_SWITCH_DEFAULT_CASE()
    6093             :         }
    6094             : 
    6095           0 :         return " unknown";
    6096             : }
    6097             : /* }}} */
    6098             : 
    6099           5 : static void zend_check_already_in_use(uint32_t type, zend_string *old_name, zend_string *new_name, zend_string *check_name) /* {{{ */
    6100             : {
    6101           5 :         if (zend_string_equals_ci(old_name, check_name)) {
    6102           1 :                 return;
    6103             :         }
    6104             : 
    6105           4 :         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use%s %s as %s because the name "
    6106             :                 "is already in use", zend_get_use_type_str(type), ZSTR_VAL(old_name), ZSTR_VAL(new_name));
    6107             : }
    6108             : /* }}} */
    6109             : 
    6110         135 : void zend_compile_use(zend_ast *ast) /* {{{ */
    6111             : {
    6112         135 :         zend_ast_list *list = zend_ast_get_list(ast);
    6113             :         uint32_t i;
    6114         135 :         zend_string *current_ns = FC(current_namespace);
    6115         135 :         uint32_t type = ast->attr;
    6116         135 :         HashTable *current_import = zend_get_import_ht(type);
    6117         135 :         zend_bool case_sensitive = type == T_CONST;
    6118             : 
    6119         266 :         for (i = 0; i < list->children; ++i) {
    6120         143 :                 zend_ast *use_ast = list->child[i];
    6121         143 :                 zend_ast *old_name_ast = use_ast->child[0];
    6122         143 :                 zend_ast *new_name_ast = use_ast->child[1];
    6123         143 :                 zend_string *old_name = zend_ast_get_str(old_name_ast);
    6124             :                 zend_string *new_name, *lookup_name;
    6125             : 
    6126         143 :                 if (new_name_ast) {
    6127          59 :                         new_name = zend_string_copy(zend_ast_get_str(new_name_ast));
    6128             :                 } else {
    6129             :                         const char *unqualified_name;
    6130             :                         size_t unqualified_name_len;
    6131          84 :                         if (zend_get_unqualified_name(old_name, &unqualified_name, &unqualified_name_len)) {
    6132             :                                 /* The form "use A\B" is equivalent to "use A\B as B" */
    6133         142 :                                 new_name = zend_string_init(unqualified_name, unqualified_name_len, 0);
    6134             :                         } else {
    6135          13 :                                 new_name = zend_string_copy(old_name);
    6136             : 
    6137          13 :                                 if (!current_ns) {
    6138           4 :                                         if (type == T_CLASS && zend_string_equals_literal(new_name, "strict")) {
    6139           0 :                                                 zend_error_noreturn(E_COMPILE_ERROR,
    6140             :                                                         "You seem to be trying to use a different language...");
    6141             :                                         }
    6142             : 
    6143           4 :                                         zend_error(E_WARNING, "The use statement with non-compound name '%s' "
    6144             :                                                 "has no effect", ZSTR_VAL(new_name));
    6145             :                                 }
    6146             :                         }
    6147             :                 }
    6148             : 
    6149         143 :                 if (case_sensitive) {
    6150          29 :                         lookup_name = zend_string_copy(new_name);
    6151             :                 } else {
    6152         114 :                         lookup_name = zend_string_tolower(new_name);
    6153             :                 }
    6154             : 
    6155         143 :                 if (type == T_CLASS && zend_is_reserved_class_name(new_name)) {
    6156           5 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use %s as %s because '%s' "
    6157             :                                 "is a special class name", ZSTR_VAL(old_name), ZSTR_VAL(new_name), ZSTR_VAL(new_name));
    6158             :                 }
    6159             : 
    6160         138 :                 if (current_ns) {
    6161         170 :                         zend_string *ns_name = zend_string_alloc(ZSTR_LEN(current_ns) + 1 + ZSTR_LEN(new_name), 0);
    6162          85 :                         zend_str_tolower_copy(ZSTR_VAL(ns_name), ZSTR_VAL(current_ns), ZSTR_LEN(current_ns));
    6163          85 :                         ZSTR_VAL(ns_name)[ZSTR_LEN(current_ns)] = '\\';
    6164          85 :                         memcpy(ZSTR_VAL(ns_name) + ZSTR_LEN(current_ns) + 1, ZSTR_VAL(lookup_name), ZSTR_LEN(lookup_name));
    6165             : 
    6166          85 :                         if (zend_hash_exists(CG(class_table), ns_name)) {
    6167           2 :                                 zend_check_already_in_use(type, old_name, new_name, ns_name);
    6168             :                         }
    6169             : 
    6170             :                         zend_string_free(ns_name);
    6171             :                 } else {
    6172          53 :                         switch (type) {
    6173             :                                 case T_CLASS:
    6174             :                                 {
    6175          42 :                                         zend_class_entry *ce = zend_hash_find_ptr(CG(class_table), lookup_name);
    6176          28 :                                         if (ce && ce->type == ZEND_USER_CLASS
    6177           7 :                                                 && ce->info.user.filename == CG(compiled_filename)
    6178             :                                         ) {
    6179           1 :                                                 zend_check_already_in_use(type, old_name, new_name, lookup_name);
    6180             :                                         }
    6181          20 :                                         break;
    6182             :                                 }
    6183             :                                 case T_FUNCTION:
    6184             :                                 {
    6185          34 :                                         zend_function *fn = zend_hash_find_ptr(CG(function_table), lookup_name);
    6186          20 :                                         if (fn && fn->type == ZEND_USER_FUNCTION
    6187           3 :                                                 && fn->op_array.filename == CG(compiled_filename)
    6188             :                                         ) {
    6189           1 :                                                 zend_check_already_in_use(type, old_name, new_name, lookup_name);
    6190             :                                         }
    6191          16 :                                         break;
    6192             :                                 }
    6193             :                                 case T_CONST:
    6194             :                                 {
    6195          15 :                                         zend_string *filename = zend_hash_find_ptr(&CG(const_filenames), lookup_name);
    6196          15 :                                         if (filename && filename == CG(compiled_filename)) {
    6197           1 :                                                 zend_check_already_in_use(type, old_name, new_name, lookup_name);
    6198             :                                         }
    6199             :                                         break;
    6200             :                                 }
    6201             :                                 EMPTY_SWITCH_DEFAULT_CASE()
    6202             :                         }
    6203             :                 }
    6204             : 
    6205             :                 zend_string_addref(old_name);
    6206         134 :                 if (!zend_hash_add_ptr(current_import, lookup_name, old_name)) {
    6207           3 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use%s %s as %s because the name "
    6208             :                                 "is already in use", zend_get_use_type_str(type), ZSTR_VAL(old_name), ZSTR_VAL(new_name));
    6209             :                 }
    6210             : 
    6211             :                 zend_string_release(lookup_name);
    6212             :                 zend_string_release(new_name);
    6213             :         }
    6214         123 : }
    6215             : /* }}} */
    6216             : 
    6217          14 : void zend_compile_group_use(zend_ast *ast) /* {{{ */
    6218             : {
    6219             :         uint32_t i;
    6220          28 :         zend_string *ns = zend_ast_get_str(ast->child[0]);
    6221          28 :         zend_ast_list *list = zend_ast_get_list(ast->child[1]);
    6222             : 
    6223          55 :         for (i = 0; i < list->children; i++) {
    6224          41 :                 zend_ast *inline_use, *use = list->child[i];
    6225          82 :                 zval *name_zval = zend_ast_get_zval(use->child[0]);
    6226          41 :                 zend_string *name = Z_STR_P(name_zval);
    6227          41 :                 zend_string *compound_ns = zend_concat_names(ZSTR_VAL(ns), ZSTR_LEN(ns), ZSTR_VAL(name), ZSTR_LEN(name));
    6228             :                 zend_string_release(name);
    6229          41 :                 ZVAL_STR(name_zval, compound_ns);
    6230          41 :                 inline_use = zend_ast_create_list(1, ZEND_AST_USE, use);
    6231          41 :                 inline_use->attr = ast->attr ? ast->attr : use->attr;
    6232          41 :                 zend_compile_use(inline_use);
    6233             :         }
    6234          14 : }
    6235             : /* }}} */
    6236             : 
    6237         217 : void zend_compile_const_decl(zend_ast *ast) /* {{{ */
    6238             : {
    6239         217 :         zend_ast_list *list = zend_ast_get_list(ast);
    6240             :         uint32_t i;
    6241         427 :         for (i = 0; i < list->children; ++i) {
    6242         218 :                 zend_ast *const_ast = list->child[i];
    6243         218 :                 zend_ast *name_ast = const_ast->child[0];
    6244         218 :                 zend_ast *value_ast = const_ast->child[1];
    6245         218 :                 zend_string *unqualified_name = zend_ast_get_str(name_ast);
    6246             : 
    6247             :                 zend_string *name;
    6248             :                 znode name_node, value_node;
    6249         218 :                 zval *value_zv = &value_node.u.constant;
    6250             : 
    6251         218 :                 value_node.op_type = IS_CONST;
    6252         218 :                 zend_const_expr_to_zval(value_zv, value_ast);
    6253             : 
    6254         213 :                 if (zend_lookup_reserved_const(ZSTR_VAL(unqualified_name), ZSTR_LEN(unqualified_name))) {
    6255           1 :                         zend_error_noreturn(E_COMPILE_ERROR,
    6256             :                                 "Cannot redeclare constant '%s'", ZSTR_VAL(unqualified_name));
    6257             :                 }
    6258             : 
    6259         212 :                 name = zend_prefix_with_ns(unqualified_name);
    6260         212 :                 name = zend_new_interned_string(name);
    6261             : 
    6262         212 :                 if (FC(imports_const)) {
    6263          10 :                         zend_string *import_name = zend_hash_find_ptr(FC(imports_const), unqualified_name);
    6264           7 :                         if (import_name && !zend_string_equals(import_name, name)) {
    6265           2 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare const %s because "
    6266             :                                         "the name is already in use", ZSTR_VAL(name));
    6267             :                         }
    6268             :                 }
    6269             : 
    6270         210 :                 name_node.op_type = IS_CONST;
    6271         210 :                 ZVAL_STR(&name_node.u.constant, name);
    6272             : 
    6273         210 :                 zend_emit_op(NULL, ZEND_DECLARE_CONST, &name_node, &value_node);
    6274             : 
    6275         210 :                 zend_hash_add_ptr(&CG(const_filenames), name, CG(compiled_filename));
    6276             :         }
    6277         209 : }
    6278             : /* }}}*/
    6279             : 
    6280         263 : void zend_compile_namespace(zend_ast *ast) /* {{{ */
    6281             : {
    6282         263 :         zend_ast *name_ast = ast->child[0];
    6283         263 :         zend_ast *stmt_ast = ast->child[1];
    6284             :         zend_string *name;
    6285         263 :         zend_bool with_bracket = stmt_ast != NULL;
    6286             : 
    6287             :         /* handle mixed syntax declaration or nested namespaces */
    6288         263 :         if (!FC(has_bracketed_namespaces)) {
    6289         213 :                 if (FC(current_namespace)) {
    6290             :                         /* previous namespace declarations were unbracketed */
    6291           7 :                         if (with_bracket) {
    6292           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot mix bracketed namespace declarations "
    6293             :                                         "with unbracketed namespace declarations");
    6294             :                         }
    6295             :                 }
    6296             :         } else {
    6297             :                 /* previous namespace declarations were bracketed */
    6298          50 :                 if (!with_bracket) {
    6299           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot mix bracketed namespace declarations "
    6300             :                                 "with unbracketed namespace declarations");
    6301          49 :                 } else if (FC(current_namespace) || FC(in_namespace)) {
    6302           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Namespace declarations cannot be nested");
    6303             :                 }
    6304             :         }
    6305             : 
    6306         579 :         if (((!with_bracket && !FC(current_namespace))
    6307         319 :                  || (with_bracket && !FC(has_bracketed_namespaces))) && CG(active_op_array)->last > 0
    6308             :         ) {
    6309             :                 /* ignore ZEND_EXT_STMT and ZEND_TICKS */
    6310           3 :                 uint32_t num = CG(active_op_array)->last;
    6311          13 :                 while (num > 0 &&
    6312           3 :                        (CG(active_op_array)->opcodes[num-1].opcode == ZEND_EXT_STMT ||
    6313           3 :                         CG(active_op_array)->opcodes[num-1].opcode == ZEND_TICKS)) {
    6314           1 :                         --num;
    6315             :                 }
    6316           3 :                 if (num > 0) {
    6317           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Namespace declaration statement has to be "
    6318             :                                 "the very first statement or after any declare call in the script");
    6319             :                 }
    6320             :         }
    6321             : 
    6322         258 :         if (FC(current_namespace)) {
    6323           6 :                 zend_string_release(FC(current_namespace));
    6324             :         }
    6325             : 
    6326         258 :         if (name_ast) {
    6327         215 :                 name = zend_ast_get_str(name_ast);
    6328             : 
    6329         215 :                 if (ZEND_FETCH_CLASS_DEFAULT != zend_get_class_fetch_type(name)) {
    6330           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use '%s' as namespace name", ZSTR_VAL(name));
    6331             :                 }
    6332             : 
    6333         214 :                 FC(current_namespace) = zend_string_copy(name);
    6334             :         } else {
    6335          43 :                 FC(current_namespace) = NULL;
    6336             :         }
    6337             : 
    6338         257 :         zend_reset_import_tables();
    6339             : 
    6340         257 :         FC(in_namespace) = 1;
    6341         257 :         if (with_bracket) {
    6342         112 :                 FC(has_bracketed_namespaces) = 1;
    6343             :         }
    6344             : 
    6345         257 :         if (stmt_ast) {
    6346         112 :                 zend_compile_top_stmt(stmt_ast);
    6347          96 :                 zend_end_namespace();
    6348             :         }
    6349         241 : }
    6350             : /* }}} */
    6351             : 
    6352         276 : void zend_compile_halt_compiler(zend_ast *ast) /* {{{ */
    6353             : {
    6354         276 :         zend_ast *offset_ast = ast->child[0];
    6355         276 :         zend_long offset = Z_LVAL_P(zend_ast_get_zval(offset_ast));
    6356             : 
    6357             :         zend_string *filename, *name;
    6358         276 :         const char const_name[] = "__COMPILER_HALT_OFFSET__";
    6359             : 
    6360         276 :         if (FC(has_bracketed_namespaces) && FC(in_namespace)) {
    6361           0 :                 zend_error_noreturn(E_COMPILE_ERROR,
    6362             :                         "__HALT_COMPILER() can only be used from the outermost scope");
    6363             :         }
    6364             : 
    6365         276 :         filename = zend_get_compiled_filename();
    6366         276 :         name = zend_mangle_property_name(const_name, sizeof(const_name) - 1,
    6367             :                 ZSTR_VAL(filename), ZSTR_LEN(filename), 0);
    6368             : 
    6369         276 :         zend_register_long_constant(ZSTR_VAL(name), ZSTR_LEN(name), offset, CONST_CS, 0);
    6370             :         zend_string_release(name);
    6371         276 : }
    6372             : /* }}} */
    6373             : 
    6374       12169 : static zend_bool zend_try_ct_eval_magic_const(zval *zv, zend_ast *ast) /* {{{ */
    6375             : {
    6376       12169 :         zend_op_array *op_array = CG(active_op_array);
    6377       12169 :         zend_class_entry *ce = CG(active_class_entry);
    6378             : 
    6379       12169 :         switch (ast->attr) {
    6380             :                 case T_LINE:
    6381          25 :                         ZVAL_LONG(zv, ast->lineno);
    6382          25 :                         break;
    6383             :                 case T_FILE:
    6384       10189 :                         ZVAL_STR_COPY(zv, CG(compiled_filename));
    6385       10189 :                         break;
    6386             :                 case T_DIR:
    6387             :                 {
    6388         701 :                         zend_string *filename = CG(compiled_filename);
    6389        1402 :                         zend_string *dirname = zend_string_init(ZSTR_VAL(filename), ZSTR_LEN(filename), 0);
    6390         701 :                         zend_dirname(ZSTR_VAL(dirname), ZSTR_LEN(dirname));
    6391             : 
    6392         701 :                         if (strcmp(ZSTR_VAL(dirname), ".") == 0) {
    6393           0 :                                 dirname = zend_string_extend(dirname, MAXPATHLEN, 0);
    6394             : #if HAVE_GETCWD
    6395           0 :                                 ZEND_IGNORE_VALUE(VCWD_GETCWD(ZSTR_VAL(dirname), MAXPATHLEN));
    6396             : #elif HAVE_GETWD
    6397             :                                 ZEND_IGNORE_VALUE(VCWD_GETWD(ZSTR_VAL(dirname)));
    6398             : #endif
    6399             :                         }
    6400             : 
    6401         701 :                         ZSTR_LEN(dirname) = strlen(ZSTR_VAL(dirname));
    6402         701 :                         ZVAL_STR(zv, dirname);
    6403         701 :                         break;
    6404             :                 }
    6405             :                 case T_FUNC_C:
    6406         262 :                         if (op_array && op_array->function_name) {
    6407         130 :                                 ZVAL_STR_COPY(zv, op_array->function_name);
    6408             :                         } else {
    6409           2 :                                 ZVAL_EMPTY_STRING(zv);
    6410             :                         }
    6411         132 :                         break;
    6412             :                 case T_METHOD_C:
    6413        1007 :                         if ((op_array && !op_array->scope && op_array->function_name) || (op_array->fn_flags & ZEND_ACC_CLOSURE)) {
    6414          25 :                                 ZVAL_STR_COPY(zv, op_array->function_name);
    6415         957 :                         } else if (ce) {
    6416        1911 :                                 if (op_array && op_array->function_name) {
    6417         955 :                                         ZVAL_NEW_STR(zv, zend_concat3(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), "::", 2,
    6418             :                                                 ZSTR_VAL(op_array->function_name), ZSTR_LEN(op_array->function_name)));
    6419             :                                 } else {
    6420           1 :                                         ZVAL_STR_COPY(zv, ce->name);
    6421             :                                 }
    6422           1 :                         } else if (op_array && op_array->function_name) {
    6423           0 :                                 ZVAL_STR_COPY(zv, op_array->function_name);
    6424             :                         } else {
    6425           1 :                                 ZVAL_EMPTY_STRING(zv);
    6426             :                         }
    6427         982 :                         break;
    6428             :                 case T_CLASS_C:
    6429         101 :                         if (ce) {
    6430         100 :                                 if ((ce->ce_flags & ZEND_ACC_TRAIT) != 0) {
    6431           6 :                                         return 0;
    6432             :                                 } else {
    6433          94 :                                         ZVAL_STR_COPY(zv, ce->name);
    6434             :                                 }
    6435             :                         } else {
    6436           1 :                                 ZVAL_EMPTY_STRING(zv);
    6437             :                         }
    6438          95 :                         break;
    6439             :                 case T_TRAIT_C:
    6440           6 :                         if (ce && (ce->ce_flags & ZEND_ACC_TRAIT) != 0) {
    6441           1 :                                 ZVAL_STR_COPY(zv, ce->name);
    6442             :                         } else {
    6443           4 :                                 ZVAL_EMPTY_STRING(zv);
    6444             :                         }
    6445           5 :                         break;
    6446             :                 case T_NS_C:
    6447          34 :                         if (FC(current_namespace)) {
    6448          25 :                                 ZVAL_STR_COPY(zv, FC(current_namespace));
    6449             :                         } else {
    6450           9 :                                 ZVAL_EMPTY_STRING(zv);
    6451             :                         }
    6452             :                         break;
    6453             :                 EMPTY_SWITCH_DEFAULT_CASE()
    6454             :         }
    6455             : 
    6456       12163 :         return 1;
    6457             : }
    6458             : /* }}} */
    6459             : 
    6460       12827 : ZEND_API zend_bool zend_binary_op_produces_numeric_string_error(uint32_t opcode, zval *op1, zval *op2) /* {{{ */
    6461             : {
    6462       12827 :         if (!(opcode == ZEND_ADD || opcode == ZEND_SUB || opcode == ZEND_MUL || opcode == ZEND_DIV
    6463             :                 || opcode == ZEND_POW || opcode == ZEND_MOD || opcode == ZEND_SL || opcode == ZEND_SR
    6464             :                 || opcode == ZEND_BW_OR || opcode == ZEND_BW_AND || opcode == ZEND_BW_XOR)) {
    6465        4652 :                 return 0;
    6466             :         }
    6467             : 
    6468             :         /* While basic arithmetic operators always produce numeric string errors,
    6469             :          * bitwise operators don't produce errors if both operands are strings */
    6470        8823 :         if ((opcode == ZEND_BW_OR || opcode == ZEND_BW_AND || opcode == ZEND_BW_XOR)
    6471             :                 && Z_TYPE_P(op1) == IS_STRING && Z_TYPE_P(op2) == IS_STRING) {
    6472           0 :                 return 0;
    6473             :         }
    6474             : 
    6475        8225 :         if (Z_TYPE_P(op1) == IS_STRING
    6476          50 :                 && !is_numeric_string(Z_STRVAL_P(op1), Z_STRLEN_P(op1), NULL, NULL, 0)) {
    6477          32 :                 return 1;
    6478             :         }
    6479             : 
    6480        8167 :         if (Z_TYPE_P(op2) == IS_STRING
    6481          24 :                 && !is_numeric_string(Z_STRVAL_P(op2), Z_STRLEN_P(op2), NULL, NULL, 0)) {
    6482          10 :                 return 1;
    6483             :         }
    6484             : 
    6485        8133 :         return 0;
    6486             : }
    6487             : /* }}} */
    6488             : 
    6489       12832 : static inline zend_bool zend_try_ct_eval_binary_op(zval *result, uint32_t opcode, zval *op1, zval *op2) /* {{{ */
    6490             : {
    6491       12832 :         binary_op_type fn = get_binary_op(opcode);
    6492             : 
    6493             :         /* don't evaluate division by zero at compile-time */
    6494       12879 :         if ((opcode == ZEND_DIV || opcode == ZEND_MOD) &&
    6495             :             zval_get_long(op2) == 0) {
    6496          12 :                 return 0;
    6497       12862 :         } else if ((opcode == ZEND_SL || opcode == ZEND_SR) &&
    6498             :             zval_get_long(op2) < 0) {
    6499           0 :                 return 0;
    6500             :         }
    6501             : 
    6502             :         /* don't evaluate numeric string error-producing operations at compile-time */
    6503       12820 :         if (zend_binary_op_produces_numeric_string_error(opcode, op1, op2)) {
    6504          42 :                 return 0;
    6505             :         }
    6506             : 
    6507       12778 :         fn(result, op1, op2);
    6508       12776 :         return 1;
    6509             : }
    6510             : /* }}} */
    6511             : 
    6512         251 : static inline void zend_ct_eval_unary_op(zval *result, uint32_t opcode, zval *op) /* {{{ */
    6513             : {
    6514         251 :         unary_op_type fn = get_unary_op(opcode);
    6515         251 :         fn(result, op);
    6516         251 : }
    6517             : /* }}} */
    6518             : 
    6519        6903 : static inline zend_bool zend_try_ct_eval_unary_pm(zval *result, zend_ast_kind kind, zval *op) /* {{{ */
    6520             : {
    6521             :         zval left;
    6522        6903 :         ZVAL_LONG(&left, (kind == ZEND_AST_UNARY_PLUS) ? 1 : -1);
    6523        6903 :         return zend_try_ct_eval_binary_op(result, ZEND_MUL, &left, op);
    6524             : }
    6525             : /* }}} */
    6526             : 
    6527          25 : static inline void zend_ct_eval_greater(zval *result, zend_ast_kind kind, zval *op1, zval *op2) /* {{{ */
    6528             : {
    6529             :         binary_op_type fn = kind == ZEND_AST_GREATER
    6530          25 :                 ? is_smaller_function : is_smaller_or_equal_function;
    6531          25 :         fn(result, op2, op1);
    6532          25 : }
    6533             : /* }}} */
    6534             : 
    6535       30826 : static zend_bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
    6536             : {
    6537       30826 :         zend_ast_list *list = zend_ast_get_list(ast);
    6538             :         uint32_t i;
    6539       30826 :         zend_bool is_constant = 1;
    6540             : 
    6541       30826 :         if (ast->attr == ZEND_ARRAY_SYNTAX_LIST) {
    6542           0 :                 zend_error(E_COMPILE_ERROR, "Cannot use list() as standalone expression");
    6543             :         }
    6544             : 
    6545             :         /* First ensure that *all* child nodes are constant and by-val */
    6546      141700 :         for (i = 0; i < list->children; ++i) {
    6547      110877 :                 zend_ast *elem_ast = list->child[i];
    6548             : 
    6549      110877 :                 if (elem_ast == NULL) {
    6550           2 :                         zend_error(E_COMPILE_ERROR, "Cannot use empty array elements in arrays");
    6551             :                 }
    6552             : 
    6553      110875 :                 zend_eval_const_expr(&elem_ast->child[0]);
    6554      110874 :                 zend_eval_const_expr(&elem_ast->child[1]);
    6555             : 
    6556      342660 :                 if (elem_ast->attr /* by_ref */ || elem_ast->child[0]->kind != ZEND_AST_ZVAL
    6557      231786 :                         || (elem_ast->child[1] && elem_ast->child[1]->kind != ZEND_AST_ZVAL)
    6558             :                 ) {
    6559       14203 :                         is_constant = 0;
    6560             :                 }
    6561             :         }
    6562             : 
    6563       30823 :         if (!is_constant) {
    6564        6101 :                 return 0;
    6565             :         }
    6566             : 
    6567       24722 :         array_init_size(result, list->children);
    6568      101167 :         for (i = 0; i < list->children; ++i) {
    6569       76445 :                 zend_ast *elem_ast = list->child[i];
    6570       76445 :                 zend_ast *value_ast = elem_ast->child[0];
    6571       76445 :                 zend_ast *key_ast = elem_ast->child[1];
    6572             : 
    6573       76445 :                 zval *value = zend_ast_get_zval(value_ast);
    6574       76445 :                 if (Z_REFCOUNTED_P(value)) Z_ADDREF_P(value);
    6575             : 
    6576       76445 :                 if (key_ast) {
    6577       17987 :                         zval *key = zend_ast_get_zval(key_ast);
    6578       17987 :                         switch (Z_TYPE_P(key)) {
    6579             :                                 case IS_LONG:
    6580        3075 :                                         zend_hash_index_update(Z_ARRVAL_P(result), Z_LVAL_P(key), value);
    6581        3075 :                                         break;
    6582             :                                 case IS_STRING:
    6583       14388 :                                         zend_symtable_update(Z_ARRVAL_P(result), Z_STR_P(key), value);
    6584       14388 :                                         break;
    6585             :                                 case IS_DOUBLE:
    6586         524 :                                         zend_hash_index_update(Z_ARRVAL_P(result),
    6587             :                                                 zend_dval_to_lval(Z_DVAL_P(key)), value);
    6588         262 :                                         break;
    6589             :                                 case IS_FALSE:
    6590          72 :                                         zend_hash_index_update(Z_ARRVAL_P(result), 0, value);
    6591          72 :                                         break;
    6592             :                                 case IS_TRUE:
    6593          76 :                                         zend_hash_index_update(Z_ARRVAL_P(result), 1, value);
    6594          76 :                                         break;
    6595             :                                 case IS_NULL:
    6596         114 :                                         zend_hash_update(Z_ARRVAL_P(result), ZSTR_EMPTY_ALLOC(), value);
    6597         114 :                                         break;
    6598             :                                 default:
    6599           0 :                                         zend_error_noreturn(E_COMPILE_ERROR, "Illegal offset type");
    6600             :                                         break;
    6601             :                         }
    6602             :                 } else {
    6603       58458 :                         zend_hash_next_index_insert(Z_ARRVAL_P(result), value);
    6604             :                 }
    6605             :         }
    6606             : 
    6607       24722 :         return 1;
    6608             : }
    6609             : /* }}} */
    6610             : 
    6611      101748 : void zend_compile_binary_op(znode *result, zend_ast *ast) /* {{{ */
    6612             : {
    6613      101748 :         zend_ast *left_ast = ast->child[0];
    6614      101748 :         zend_ast *right_ast = ast->child[1];
    6615      101748 :         uint32_t opcode = ast->attr;
    6616             : 
    6617             :         znode left_node, right_node;
    6618      101748 :         zend_compile_expr(&left_node, left_ast);
    6619      101748 :         zend_compile_expr(&right_node, right_ast);
    6620             : 
    6621      101748 :         if (left_node.op_type == IS_CONST && right_node.op_type == IS_CONST) {
    6622        5469 :                 if (zend_try_ct_eval_binary_op(&result->u.constant, opcode,
    6623             :                                 &left_node.u.constant, &right_node.u.constant)
    6624             :                 ) {
    6625        5425 :                         result->op_type = IS_CONST;
    6626        5425 :                         zval_ptr_dtor(&left_node.u.constant);
    6627        5425 :                         zval_ptr_dtor(&right_node.u.constant);
    6628        5425 :                         return;
    6629             :                 }
    6630             :         }
    6631             : 
    6632             :         do {
    6633       96323 :                 if (opcode == ZEND_IS_EQUAL || opcode == ZEND_IS_NOT_EQUAL) {
    6634       20530 :                         if (left_node.op_type == IS_CONST) {
    6635        5655 :                                 if (Z_TYPE(left_node.u.constant) == IS_FALSE) {
    6636         476 :                                         opcode = (opcode == ZEND_IS_NOT_EQUAL) ? ZEND_BOOL : ZEND_BOOL_NOT;
    6637         476 :                                         zend_emit_op_tmp(result, opcode, &right_node, NULL);
    6638         476 :                                         break;
    6639        5179 :                                 } else if (Z_TYPE(left_node.u.constant) == IS_TRUE) {
    6640           2 :                                         opcode = (opcode == ZEND_IS_EQUAL) ? ZEND_BOOL : ZEND_BOOL_NOT;
    6641           2 :                                         zend_emit_op_tmp(result, opcode, &right_node, NULL);
    6642           2 :                                         break;
    6643             :                                 }
    6644       14875 :                         } else if (right_node.op_type == IS_CONST) {
    6645       12672 :                                 if (Z_TYPE(right_node.u.constant) == IS_FALSE) {
    6646        1013 :                                         opcode = (opcode == ZEND_IS_NOT_EQUAL) ? ZEND_BOOL : ZEND_BOOL_NOT;
    6647        1013 :                                         zend_emit_op_tmp(result, opcode, &left_node, NULL);
    6648        1013 :                                         break;
    6649       11659 :                                 } else if (Z_TYPE(right_node.u.constant) == IS_TRUE) {
    6650         588 :                                         opcode = (opcode == ZEND_IS_EQUAL) ? ZEND_BOOL : ZEND_BOOL_NOT;
    6651         588 :                                         zend_emit_op_tmp(result, opcode, &left_node, NULL);
    6652         588 :                                         break;
    6653             :                                 }
    6654             :                         }
    6655             :                 }
    6656       94244 :                 if (opcode == ZEND_CONCAT) {
    6657             :                         /* convert constant operands to strings at compile-time */
    6658       44173 :                         if (left_node.op_type == IS_CONST) {
    6659        8097 :                                 convert_to_string(&left_node.u.constant);
    6660             :                         }
    6661       44173 :                         if (right_node.op_type == IS_CONST) {
    6662       25525 :                                 convert_to_string(&right_node.u.constant);
    6663             :                         }
    6664             :                 }
    6665       94244 :                 zend_emit_op_tmp(result, opcode, &left_node, &right_node);
    6666             :         } while (0);
    6667             : }
    6668             : /* }}} */
    6669             : 
    6670             : /* We do not use zend_compile_binary_op for this because we want to retain the left-to-right
    6671             :  * evaluation order. */
    6672        1582 : void zend_compile_greater(znode *result, zend_ast *ast) /* {{{ */
    6673             : {
    6674        1582 :         zend_ast *left_ast = ast->child[0];
    6675        1582 :         zend_ast *right_ast = ast->child[1];
    6676             :         znode left_node, right_node;
    6677             : 
    6678             :         ZEND_ASSERT(ast->kind == ZEND_AST_GREATER || ast->kind == ZEND_AST_GREATER_EQUAL);
    6679             : 
    6680        1582 :         zend_compile_expr(&left_node, left_ast);
    6681        1582 :         zend_compile_expr(&right_node, right_ast);
    6682             : 
    6683        1582 :         if (left_node.op_type == IS_CONST && right_node.op_type == IS_CONST) {
    6684          23 :                 result->op_type = IS_CONST;
    6685          23 :                 zend_ct_eval_greater(&result->u.constant, ast->kind,
    6686             :                         &left_node.u.constant, &right_node.u.constant);
    6687          23 :                 zval_ptr_dtor(&left_node.u.constant);
    6688          23 :                 zval_ptr_dtor(&right_node.u.constant);
    6689          23 :                 return;
    6690             :         }
    6691             : 
    6692        1559 :         zend_emit_op_tmp(result,
    6693        1559 :                 ast->kind == ZEND_AST_GREATER ? ZEND_IS_SMALLER : ZEND_IS_SMALLER_OR_EQUAL,
    6694             :                 &right_node, &left_node);
    6695             : }
    6696             : /* }}} */
    6697             : 
    6698       33626 : void zend_compile_unary_op(znode *result, zend_ast *ast) /* {{{ */
    6699             : {
    6700       33626 :         zend_ast *expr_ast = ast->child[0];
    6701       33626 :         uint32_t opcode = ast->attr;
    6702             : 
    6703             :         znode expr_node;
    6704       33626 :         zend_compile_expr(&expr_node, expr_ast);
    6705             : 
    6706       33626 :         if (expr_node.op_type == IS_CONST) {
    6707         249 :                 result->op_type = IS_CONST;
    6708         249 :                 zend_ct_eval_unary_op(&result->u.constant, opcode,
    6709             :                         &expr_node.u.constant);
    6710         249 :                 zval_ptr_dtor(&expr_node.u.constant);
    6711         249 :                 return;
    6712             :         }
    6713             : 
    6714       33377 :         zend_emit_op_tmp(result, opcode, &expr_node, NULL);
    6715             : }
    6716             : /* }}} */
    6717             : 
    6718        3483 : void zend_compile_unary_pm(znode *result, zend_ast *ast) /* {{{ */
    6719             : {
    6720        3483 :         zend_ast *expr_ast = ast->child[0];
    6721             :         znode expr_node;
    6722             :         znode lefthand_node;
    6723             : 
    6724             :         ZEND_ASSERT(ast->kind == ZEND_AST_UNARY_PLUS || ast->kind == ZEND_AST_UNARY_MINUS);
    6725             : 
    6726        3483 :         zend_compile_expr(&expr_node, expr_ast);
    6727             : 
    6728        3483 :         if (expr_node.op_type == IS_CONST) {
    6729        3429 :                 if (zend_try_ct_eval_unary_pm(&result->u.constant, ast->kind, &expr_node.u.constant)) {
    6730        3425 :                         result->op_type = IS_CONST;
    6731        3425 :                         zval_ptr_dtor(&expr_node.u.constant);
    6732        3425 :                         return;
    6733             :                 }
    6734             :         }
    6735             : 
    6736          58 :         lefthand_node.op_type = IS_CONST;
    6737          58 :         ZVAL_LONG(&lefthand_node.u.constant, (ast->kind == ZEND_AST_UNARY_PLUS) ? 1 : -1);
    6738          58 :         zend_emit_op_tmp(result, ZEND_MUL, &lefthand_node, &expr_node);
    6739             : }
    6740             : /* }}} */
    6741             : 
    6742       13706 : void zend_compile_short_circuiting(znode *result, zend_ast *ast) /* {{{ */
    6743             : {
    6744       13706 :         zend_ast *left_ast = ast->child[0];
    6745       13706 :         zend_ast *right_ast = ast->child[1];
    6746             : 
    6747             :         znode left_node, right_node;
    6748             :         zend_op *opline_jmpz, *opline_bool;
    6749             :         uint32_t opnum_jmpz;
    6750             : 
    6751             :         ZEND_ASSERT(ast->kind == ZEND_AST_AND || ast->kind == ZEND_AST_OR);
    6752             : 
    6753       13706 :         zend_compile_expr(&left_node, left_ast);
    6754             : 
    6755       13706 :         if (left_node.op_type == IS_CONST) {
    6756         150 :                 if ((ast->kind == ZEND_AST_AND && !zend_is_true(&left_node.u.constant))
    6757          77 :                  || (ast->kind == ZEND_AST_OR && zend_is_true(&left_node.u.constant))) {
    6758          14 :                         result->op_type = IS_CONST;
    6759          14 :                         ZVAL_BOOL(&result->u.constant, zend_is_true(&left_node.u.constant));
    6760             :                 } else {
    6761          45 :                         zend_compile_expr(&right_node, right_ast);
    6762             : 
    6763          45 :                         if (right_node.op_type == IS_CONST) {
    6764          37 :                                 result->op_type = IS_CONST;
    6765          37 :                                 ZVAL_BOOL(&result->u.constant, zend_is_true(&right_node.u.constant));
    6766             : 
    6767          37 :                                 zval_ptr_dtor(&right_node.u.constant);
    6768             :                         } else {
    6769           8 :                                 zend_emit_op_tmp(result, ZEND_BOOL, &right_node, NULL);
    6770             :                         }
    6771             :                 }
    6772             : 
    6773          59 :                 zval_ptr_dtor(&left_node.u.constant);
    6774          59 :                 return;
    6775             :         }
    6776             : 
    6777       13647 :         opnum_jmpz = get_next_op_number(CG(active_op_array));
    6778       13647 :         opline_jmpz = zend_emit_op(NULL, ast->kind == ZEND_AST_AND ? ZEND_JMPZ_EX : ZEND_JMPNZ_EX,
    6779             :                 &left_node, NULL);
    6780             : 
    6781       13647 :         if (left_node.op_type == IS_TMP_VAR) {
    6782       11007 :                 SET_NODE(opline_jmpz->result, &left_node);
    6783             :         } else {
    6784        2640 :                 opline_jmpz->result.var = get_temporary_variable(CG(active_op_array));
    6785        2640 :                 opline_jmpz->result_type = IS_TMP_VAR;
    6786             :         }
    6787             : 
    6788       13647 :         GET_NODE(result, opline_jmpz->result);
    6789       13647 :         zend_compile_expr(&right_node, right_ast);
    6790             : 
    6791       13647 :         opline_bool = zend_emit_op(NULL, ZEND_BOOL, &right_node, NULL);
    6792       13647 :         SET_NODE(opline_bool->result, result);
    6793             : 
    6794       13647 :         zend_update_jump_target_to_next(opnum_jmpz);
    6795             : }
    6796             : /* }}} */
    6797             : 
    6798        6134 : void zend_compile_post_incdec(znode *result, zend_ast *ast) /* {{{ */
    6799             : {
    6800        6134 :         zend_ast *var_ast = ast->child[0];
    6801             :         ZEND_ASSERT(ast->kind == ZEND_AST_POST_INC || ast->kind == ZEND_AST_POST_DEC);
    6802             : 
    6803        6134 :         zend_ensure_writable_variable(var_ast);
    6804             : 
    6805        6134 :         if (var_ast->kind == ZEND_AST_PROP) {
    6806          59 :                 zend_op *opline = zend_compile_prop_common(NULL, var_ast, BP_VAR_RW);
    6807          59 :                 opline->opcode = ast->kind == ZEND_AST_POST_INC ? ZEND_POST_INC_OBJ : ZEND_POST_DEC_OBJ;
    6808          59 :                 zend_make_tmp_result(result, opline);
    6809             :         } else {
    6810             :                 znode var_node;
    6811        6075 :                 zend_compile_var(&var_node, var_ast, BP_VAR_RW);
    6812        6075 :                 zend_emit_op_tmp(result, ast->kind == ZEND_AST_POST_INC ? ZEND_POST_INC : ZEND_POST_DEC,
    6813             :                         &var_node, NULL);
    6814             :         }
    6815        6134 : }
    6816             : /* }}} */
    6817             : 
    6818         577 : void zend_compile_pre_incdec(znode *result, zend_ast *ast) /* {{{ */
    6819             : {
    6820         577 :         zend_ast *var_ast = ast->child[0];
    6821             :         ZEND_ASSERT(ast->kind == ZEND_AST_PRE_INC || ast->kind == ZEND_AST_PRE_DEC);
    6822             : 
    6823         577 :         zend_ensure_writable_variable(var_ast);
    6824             : 
    6825         576 :         if (var_ast->kind == ZEND_AST_PROP) {
    6826          36 :                 zend_op *opline = zend_compile_prop_common(result, var_ast, BP_VAR_RW);
    6827          36 :                 opline->opcode = ast->kind == ZEND_AST_PRE_INC ? ZEND_PRE_INC_OBJ : ZEND_PRE_DEC_OBJ;
    6828             :         } else {
    6829             :                 znode var_node;
    6830         540 :                 zend_compile_var(&var_node, var_ast, BP_VAR_RW);
    6831         540 :                 zend_emit_op(result, ast->kind == ZEND_AST_PRE_INC ? ZEND_PRE_INC : ZEND_PRE_DEC,
    6832             :                         &var_node, NULL);
    6833             :         }
    6834         576 : }
    6835             : /* }}} */
    6836             : 
    6837        6577 : void zend_compile_cast(znode *result, zend_ast *ast) /* {{{ */
    6838             : {
    6839        6577 :         zend_ast *expr_ast = ast->child[0];
    6840             :         znode expr_node;
    6841             :         zend_op *opline;
    6842             : 
    6843        6577 :         zend_compile_expr(&expr_node, expr_ast);
    6844             : 
    6845        6577 :         opline = zend_emit_op_tmp(result, ZEND_CAST, &expr_node, NULL);
    6846        6577 :         opline->extended_value = ast->attr;
    6847        6577 : }
    6848             : /* }}} */
    6849             : 
    6850         214 : static void zend_compile_shorthand_conditional(znode *result, zend_ast *ast) /* {{{ */
    6851             : {
    6852         214 :         zend_ast *cond_ast = ast->child[0];
    6853         214 :         zend_ast *false_ast = ast->child[2];
    6854             : 
    6855             :         znode cond_node, false_node;
    6856             :         zend_op *opline_qm_assign;
    6857             :         uint32_t opnum_jmp_set;
    6858             : 
    6859             :         ZEND_ASSERT(ast->child[1] == NULL);
    6860             : 
    6861         214 :         zend_compile_expr(&cond_node, cond_ast);
    6862             : 
    6863         214 :         opnum_jmp_set = get_next_op_number(CG(active_op_array));
    6864         214 :         zend_emit_op_tmp(result, ZEND_JMP_SET, &cond_node, NULL);
    6865             : 
    6866         214 :         zend_compile_expr(&false_node, false_ast);
    6867             : 
    6868         214 :         opline_qm_assign = zend_emit_op_tmp(NULL, ZEND_QM_ASSIGN, &false_node, NULL);
    6869         214 :         SET_NODE(opline_qm_assign->result, result);
    6870             : 
    6871         214 :         zend_update_jump_target_to_next(opnum_jmp_set);
    6872         214 : }
    6873             : /* }}} */
    6874             : 
    6875       25848 : void zend_compile_conditional(znode *result, zend_ast *ast) /* {{{ */
    6876             : {
    6877       25848 :         zend_ast *cond_ast = ast->child[0];
    6878       25848 :         zend_ast *true_ast = ast->child[1];
    6879       25848 :         zend_ast *false_ast = ast->child[2];
    6880             : 
    6881             :         znode cond_node, true_node, false_node;
    6882             :         zend_op *opline_qm_assign2;
    6883             :         uint32_t opnum_jmpz, opnum_jmp;
    6884             : 
    6885       25848 :         if (!true_ast) {
    6886         214 :                 zend_compile_shorthand_conditional(result, ast);
    6887         214 :                 return;
    6888             :         }
    6889             : 
    6890       25634 :         zend_compile_expr(&cond_node, cond_ast);
    6891             : 
    6892       25634 :         opnum_jmpz = zend_emit_cond_jump(ZEND_JMPZ, &cond_node, 0);
    6893             : 
    6894       25634 :         zend_compile_expr(&true_node, true_ast);
    6895             : 
    6896       25634 :         zend_emit_op_tmp(result, ZEND_QM_ASSIGN, &true_node, NULL);
    6897             : 
    6898       25634 :         opnum_jmp = zend_emit_jump(0);
    6899             : 
    6900       25634 :         zend_update_jump_target_to_next(opnum_jmpz);
    6901             : 
    6902       25634 :         zend_compile_expr(&false_node, false_ast);
    6903             : 
    6904       25634 :         opline_qm_assign2 = zend_emit_op(NULL, ZEND_QM_ASSIGN, &false_node, NULL);
    6905       25634 :         SET_NODE(opline_qm_assign2->result, result);
    6906             : 
    6907       25634 :         zend_update_jump_target_to_next(opnum_jmp);
    6908             : }
    6909             : /* }}} */
    6910             : 
    6911          27 : void zend_compile_coalesce(znode *result, zend_ast *ast) /* {{{ */
    6912             : {
    6913          27 :         zend_ast *expr_ast = ast->child[0];
    6914          27 :         zend_ast *default_ast = ast->child[1];
    6915             : 
    6916             :         znode expr_node, default_node;
    6917             :         zend_op *opline;
    6918             :         uint32_t opnum;
    6919             : 
    6920          27 :         zend_compile_var(&expr_node, expr_ast, BP_VAR_IS);
    6921             : 
    6922          27 :         opnum = get_next_op_number(CG(active_op_array));
    6923          27 :         zend_emit_op_tmp(result, ZEND_COALESCE, &expr_node, NULL);
    6924             : 
    6925          27 :         zend_compile_expr(&default_node, default_ast);
    6926             : 
    6927          27 :         opline = zend_emit_op_tmp(NULL, ZEND_QM_ASSIGN, &default_node, NULL);
    6928          27 :         SET_NODE(opline->result, result);
    6929             : 
    6930          27 :         opline = &CG(active_op_array)->opcodes[opnum];
    6931          27 :         opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    6932          27 : }
    6933             : /* }}} */
    6934             : 
    6935        3534 : void zend_compile_print(znode *result, zend_ast *ast) /* {{{ */
    6936             : {
    6937             :         zend_op *opline;
    6938        3534 :         zend_ast *expr_ast = ast->child[0];
    6939             : 
    6940             :         znode expr_node;
    6941        3534 :         zend_compile_expr(&expr_node, expr_ast);
    6942             : 
    6943        3534 :         opline = zend_emit_op(NULL, ZEND_ECHO, &expr_node, NULL);
    6944        3534 :         opline->extended_value = 1;
    6945             : 
    6946        3534 :         result->op_type = IS_CONST;
    6947        3534 :         ZVAL_LONG(&result->u.constant, 1);
    6948        3534 : }
    6949             : /* }}} */
    6950             : 
    6951       17371 : void zend_compile_exit(znode *result, zend_ast *ast) /* {{{ */
    6952             : {
    6953       17371 :         zend_ast *expr_ast = ast->child[0];
    6954             : 
    6955       17371 :         if (expr_ast) {
    6956             :                 znode expr_node;
    6957       16812 :                 zend_compile_expr(&expr_node, expr_ast);
    6958       16812 :                 zend_emit_op(NULL, ZEND_EXIT, &expr_node, NULL);
    6959             :         } else {
    6960         559 :                 zend_emit_op(NULL, ZEND_EXIT, NULL, NULL);
    6961             :         }
    6962             : 
    6963       17371 :         result->op_type = IS_CONST;
    6964       17371 :         ZVAL_BOOL(&result->u.constant, 1);
    6965       17371 : }
    6966             : /* }}} */
    6967             : 
    6968         260 : void zend_compile_yield(znode *result, zend_ast *ast) /* {{{ */
    6969             : {
    6970         260 :         zend_ast *value_ast = ast->child[0];
    6971         260 :         zend_ast *key_ast = ast->child[1];
    6972             : 
    6973             :         znode value_node, key_node;
    6974         260 :         znode *value_node_ptr = NULL, *key_node_ptr = NULL;
    6975             :         zend_op *opline;
    6976         260 :         zend_bool returns_by_ref = (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;
    6977             : 
    6978         260 :         zend_mark_function_as_generator();
    6979             : 
    6980         259 :         if (key_ast) {
    6981          32 :                 zend_compile_expr(&key_node, key_ast);
    6982          32 :                 key_node_ptr = &key_node;
    6983             :         }
    6984             : 
    6985         259 :         if (value_ast) {
    6986         177 :                 if (returns_by_ref && zend_is_variable(value_ast) && !zend_is_call(value_ast)) {
    6987           7 :                         zend_compile_var(&value_node, value_ast, BP_VAR_W);
    6988             :                 } else {
    6989         163 :                         zend_compile_expr(&value_node, value_ast);
    6990             :                 }
    6991         170 :                 value_node_ptr = &value_node;
    6992             :         }
    6993             : 
    6994         259 :         opline = zend_emit_op(result, ZEND_YIELD, value_node_ptr, key_node_ptr);
    6995             : 
    6996         259 :         if (value_ast && returns_by_ref && zend_is_call(value_ast)) {
    6997           2 :                 opline->extended_value = ZEND_RETURNS_FUNCTION;
    6998             :         }
    6999         259 : }
    7000             : /* }}} */
    7001             : 
    7002          41 : void zend_compile_yield_from(znode *result, zend_ast *ast) /* {{{ */
    7003             : {
    7004          41 :         zend_ast *expr_ast = ast->child[0];
    7005             :         znode expr_node;
    7006             : 
    7007          41 :         zend_mark_function_as_generator();
    7008             : 
    7009          41 :         if (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) {
    7010           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    7011             :                         "Cannot use \"yield from\" inside a by-reference generator");
    7012             :         }
    7013             : 
    7014          40 :         zend_compile_expr(&expr_node, expr_ast);
    7015          40 :         zend_emit_op_tmp(result, ZEND_YIELD_FROM, &expr_node, NULL);
    7016          40 : }
    7017             : /* }}} */
    7018             : 
    7019          75 : void zend_compile_instanceof(znode *result, zend_ast *ast) /* {{{ */
    7020             : {
    7021          75 :         zend_ast *obj_ast = ast->child[0];
    7022          75 :         zend_ast *class_ast = ast->child[1];
    7023             : 
    7024             :         znode obj_node, class_node;
    7025             :         zend_op *opline;
    7026             : 
    7027          75 :         zend_compile_expr(&obj_node, obj_ast);
    7028          75 :         if (obj_node.op_type == IS_CONST) {
    7029           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    7030             :                         "instanceof expects an object instance, constant given");
    7031             :         }
    7032             : 
    7033          74 :         zend_compile_class_ref_ex(&class_node, class_ast,
    7034             :                 ZEND_FETCH_CLASS_NO_AUTOLOAD | ZEND_FETCH_CLASS_EXCEPTION);
    7035             : 
    7036          74 :         opline = zend_emit_op_tmp(result, ZEND_INSTANCEOF, &obj_node, NULL);
    7037             : 
    7038          74 :         if (class_node.op_type == IS_CONST) {
    7039          68 :                 opline->op2_type = IS_CONST;
    7040          68 :                 opline->op2.constant = zend_add_class_name_literal(
    7041             :                         CG(active_op_array), Z_STR(class_node.u.constant));
    7042             :         } else {
    7043           6 :                 SET_NODE(opline->op2, &class_node);
    7044             :         }
    7045          74 : }
    7046             : /* }}} */
    7047             : 
    7048       13587 : void zend_compile_include_or_eval(znode *result, zend_ast *ast) /* {{{ */
    7049             : {
    7050       13587 :         zend_ast *expr_ast = ast->child[0];
    7051             :         znode expr_node;
    7052             :         zend_op *opline;
    7053             : 
    7054       13587 :         zend_do_extended_fcall_begin();
    7055       13587 :         zend_compile_expr(&expr_node, expr_ast);
    7056             : 
    7057       13587 :         opline = zend_emit_op(result, ZEND_INCLUDE_OR_EVAL, &expr_node, NULL);
    7058       13587 :         opline->extended_value = ast->attr;
    7059             : 
    7060       13587 :         zend_do_extended_fcall_end();
    7061       13587 : }
    7062             : /* }}} */
    7063             : 
    7064       13739 : void zend_compile_isset_or_empty(znode *result, zend_ast *ast) /* {{{ */
    7065             : {
    7066       13739 :         zend_ast *var_ast = ast->child[0];
    7067             : 
    7068             :         znode var_node;
    7069       13739 :         zend_op *opline = NULL;
    7070             : 
    7071             :         ZEND_ASSERT(ast->kind == ZEND_AST_ISSET || ast->kind == ZEND_AST_EMPTY);
    7072             : 
    7073       13739 :         if (!zend_is_variable(var_ast) || zend_is_call(var_ast)) {
    7074          16 :                 if (ast->kind == ZEND_AST_EMPTY) {
    7075             :                         /* empty(expr) can be transformed to !expr */
    7076          14 :                         zend_ast *not_ast = zend_ast_create_ex(ZEND_AST_UNARY_OP, ZEND_BOOL_NOT, var_ast);
    7077          14 :                         zend_compile_expr(result, not_ast);
    7078          14 :                         return;
    7079             :                 } else {
    7080           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    7081             :                                 "Cannot use isset() on the result of an expression "
    7082             :                                 "(you can use \"null !== expression\" instead)");
    7083             :                 }
    7084             :         }
    7085             : 
    7086       13723 :         switch (var_ast->kind) {
    7087             :                 case ZEND_AST_VAR:
    7088        4353 :                         if (is_this_fetch(var_ast)) {
    7089          17 :                                 opline = zend_emit_op(result, ZEND_ISSET_ISEMPTY_THIS, NULL, NULL);
    7090        4336 :                         } else if (zend_try_compile_cv(&var_node, var_ast) == SUCCESS) {
    7091        4316 :                                 opline = zend_emit_op(result, ZEND_ISSET_ISEMPTY_VAR, &var_node, NULL);
    7092        4316 :                                 opline->extended_value = ZEND_FETCH_LOCAL | ZEND_QUICK_SET;
    7093             :                         } else {
    7094          20 :                                 opline = zend_compile_simple_var_no_cv(result, var_ast, BP_VAR_IS, 0);
    7095          20 :                                 opline->opcode = ZEND_ISSET_ISEMPTY_VAR;
    7096             :                         }
    7097        4353 :                         break;
    7098             :                 case ZEND_AST_DIM:
    7099        8491 :                         opline = zend_compile_dim_common(result, var_ast, BP_VAR_IS);
    7100        8490 :                         opline->opcode = ZEND_ISSET_ISEMPTY_DIM_OBJ;
    7101        8490 :                         break;
    7102             :                 case ZEND_AST_PROP:
    7103         744 :                         opline = zend_compile_prop_common(result, var_ast, BP_VAR_IS);
    7104         744 :                         opline->opcode = ZEND_ISSET_ISEMPTY_PROP_OBJ;
    7105         744 :                         break;
    7106             :                 case ZEND_AST_STATIC_PROP:
    7107         135 :                         opline = zend_compile_static_prop_common(result, var_ast, BP_VAR_IS, 0);
    7108         135 :                         opline->opcode = ZEND_ISSET_ISEMPTY_STATIC_PROP;
    7109             :                         break;
    7110             :                 EMPTY_SWITCH_DEFAULT_CASE()
    7111             :         }
    7112             : 
    7113       13722 :         result->op_type = opline->result_type = IS_TMP_VAR;
    7114       13722 :         opline->extended_value |= ast->kind == ZEND_AST_ISSET ? ZEND_ISSET : ZEND_ISEMPTY;
    7115             : }
    7116             : /* }}} */
    7117             : 
    7118        7189 : void zend_compile_silence(znode *result, zend_ast *ast) /* {{{ */
    7119             : {
    7120        7189 :         zend_ast *expr_ast = ast->child[0];
    7121             :         znode silence_node;
    7122             :         uint32_t range;
    7123             : 
    7124        7189 :         range = zend_start_live_range(CG(active_op_array), get_next_op_number(CG(active_op_array)));
    7125        7189 :         zend_emit_op_tmp(&silence_node, ZEND_BEGIN_SILENCE, NULL, NULL);
    7126             : 
    7127        7189 :         if (expr_ast->kind == ZEND_AST_VAR) {
    7128             :                 /* For @$var we need to force a FETCH instruction, otherwise the CV access will
    7129             :                  * happen outside the silenced section. */
    7130        1479 :                 zend_compile_simple_var_no_cv(result, expr_ast, BP_VAR_R, 0 );
    7131             :         } else {
    7132        5710 :                 zend_compile_expr(result, expr_ast);
    7133             :         }
    7134             : 
    7135             :         /* Store BEGIN_SILENCE/END_SILENCE pair to restore previous
    7136             :          * EG(error_reporting) value on exception */
    7137        7189 :         zend_end_live_range(CG(active_op_array), range, get_next_op_number(CG(active_op_array)),
    7138             :                 ZEND_LIVE_SILENCE, silence_node.u.op.var);
    7139             : 
    7140        7189 :         zend_emit_op(NULL, ZEND_END_SILENCE, &silence_node, NULL);
    7141        7189 : }
    7142             : /* }}} */
    7143             : 
    7144         121 : void zend_compile_shell_exec(znode *result, zend_ast *ast) /* {{{ */
    7145             : {
    7146         121 :         zend_ast *expr_ast = ast->child[0];
    7147             : 
    7148             :         zval fn_name;
    7149             :         zend_ast *name_ast, *args_ast, *call_ast;
    7150             : 
    7151         242 :         ZVAL_STRING(&fn_name, "shell_exec");
    7152         121 :         name_ast = zend_ast_create_zval(&fn_name);
    7153         121 :         args_ast = zend_ast_create_list(1, ZEND_AST_ARG_LIST, expr_ast);
    7154         121 :         call_ast = zend_ast_create(ZEND_AST_CALL, name_ast, args_ast);
    7155             : 
    7156         121 :         zend_compile_expr(result, call_ast);
    7157             : 
    7158         121 :         zval_ptr_dtor(&fn_name);
    7159         121 : }
    7160             : /* }}} */
    7161             : 
    7162       19021 : void zend_compile_array(znode *result, zend_ast *ast) /* {{{ */
    7163             : {
    7164       19021 :         zend_ast_list *list = zend_ast_get_list(ast);
    7165             :         zend_op *opline;
    7166       19021 :         uint32_t i, opnum_init = -1;
    7167       19021 :         zend_bool packed = 1;
    7168             : 
    7169       19021 :         if (zend_try_ct_eval_array(&result->u.constant, ast)) {
    7170       14017 :                 result->op_type = IS_CONST;
    7171       14017 :                 return;
    7172             :         }
    7173             : 
    7174       36552 :         for (i = 0; i < list->children; ++i) {
    7175       31551 :                 zend_ast *elem_ast = list->child[i];
    7176             :                 zend_ast *value_ast, *key_ast;
    7177             :                 zend_bool by_ref;
    7178       31551 :                 znode value_node, key_node, *key_node_ptr = NULL;
    7179             : 
    7180       31551 :                 if (elem_ast == NULL) {
    7181           0 :                         zend_error(E_COMPILE_ERROR, "Cannot use empty array elements in arrays");
    7182             :                 }
    7183             : 
    7184       31551 :                 value_ast = elem_ast->child[0];
    7185       31551 :                 key_ast = elem_ast->child[1];
    7186       31551 :                 by_ref = elem_ast->attr;
    7187             : 
    7188       31551 :                 if (key_ast) {
    7189       10928 :                         zend_compile_expr(&key_node, key_ast);
    7190       10928 :                         zend_handle_numeric_op(&key_node);
    7191       10928 :                         key_node_ptr = &key_node;
    7192             :                 }
    7193             : 
    7194       31551 :                 if (by_ref) {
    7195         157 :                         zend_ensure_writable_variable(value_ast);
    7196         157 :                         zend_compile_var(&value_node, value_ast, BP_VAR_W);
    7197             :                 } else {
    7198       31394 :                         zend_compile_expr(&value_node, value_ast);
    7199             :                 }
    7200             : 
    7201       31551 :                 if (i == 0) {
    7202        5001 :                         opnum_init = get_next_op_number(CG(active_op_array));
    7203        5001 :                         opline = zend_emit_op_tmp(result, ZEND_INIT_ARRAY, &value_node, key_node_ptr);
    7204        5001 :                         opline->extended_value = list->children << ZEND_ARRAY_SIZE_SHIFT;
    7205             :                 } else {
    7206       26550 :                         opline = zend_emit_op(NULL, ZEND_ADD_ARRAY_ELEMENT,
    7207             :                                 &value_node, key_node_ptr);
    7208       26550 :                         SET_NODE(opline->result, result);
    7209             :                 }
    7210       31551 :                 opline->extended_value |= by_ref;
    7211             : 
    7212       42266 :                 if (key_ast && key_node.op_type == IS_CONST && Z_TYPE(key_node.u.constant) == IS_STRING) {
    7213        9944 :                         packed = 0;
    7214             :                 }
    7215             :         }
    7216             : 
    7217             :         /* Handle empty array */
    7218        5001 :         if (!list->children) {
    7219           0 :                 zend_emit_op_tmp(result, ZEND_INIT_ARRAY, NULL, NULL);
    7220             :         }
    7221             : 
    7222             :         /* Add a flag to INIT_ARRAY if we know this array cannot be packed */
    7223        5001 :         if (!packed) {
    7224             :                 ZEND_ASSERT(opnum_init != (uint32_t)-1);
    7225        2009 :                 opline = &CG(active_op_array)->opcodes[opnum_init];
    7226        2009 :                 opline->extended_value |= ZEND_ARRAY_NOT_PACKED;
    7227             :         }
    7228             : }
    7229             : /* }}} */
    7230             : 
    7231       74745 : void zend_compile_const(znode *result, zend_ast *ast) /* {{{ */
    7232             : {
    7233       74745 :         zend_ast *name_ast = ast->child[0];
    7234             : 
    7235             :         zend_op *opline;
    7236             : 
    7237             :         zend_bool is_fully_qualified;
    7238       74745 :         zend_string *orig_name = zend_ast_get_str(name_ast);
    7239       74745 :         zend_string *resolved_name = zend_resolve_const_name(orig_name, name_ast->attr, &is_fully_qualified);
    7240             : 
    7241       74745 :         if (zend_string_equals_literal(resolved_name, "__COMPILER_HALT_OFFSET__") || (name_ast->attr != ZEND_NAME_RELATIVE && zend_string_equals_literal(orig_name, "__COMPILER_HALT_OFFSET__"))) {
    7242          11 :                 zend_ast *last = CG(ast);
    7243             : 
    7244          33 :                 while (last->kind == ZEND_AST_STMT_LIST) {
    7245          11 :                         zend_ast_list *list = zend_ast_get_list(last);
    7246          11 :                         last = list->child[list->children-1];
    7247             :                 }
    7248          11 :                 if (last->kind == ZEND_AST_HALT_COMPILER) {
    7249          11 :                         result->op_type = IS_CONST;
    7250          22 :                         ZVAL_LONG(&result->u.constant, Z_LVAL_P(zend_ast_get_zval(last->child[0])));
    7251             :                         zend_string_release(resolved_name);
    7252          11 :                         return;
    7253             :                 }
    7254             :         }
    7255             : 
    7256       74734 :         if (zend_try_ct_eval_const(&result->u.constant, resolved_name, is_fully_qualified)) {
    7257       69026 :                 result->op_type = IS_CONST;
    7258             :                 zend_string_release(resolved_name);
    7259       69026 :                 return;
    7260             :         }
    7261             : 
    7262        5708 :         opline = zend_emit_op_tmp(result, ZEND_FETCH_CONSTANT, NULL, NULL);
    7263        5708 :         opline->op2_type = IS_CONST;
    7264             : 
    7265        5708 :         if (is_fully_qualified) {
    7266          68 :                 opline->op2.constant = zend_add_const_name_literal(
    7267             :                         CG(active_op_array), resolved_name, 0);
    7268             :         } else {
    7269        5640 :                 opline->extended_value = IS_CONSTANT_UNQUALIFIED;
    7270        5640 :                 if (FC(current_namespace)) {
    7271          27 :                         opline->extended_value |= IS_CONSTANT_IN_NAMESPACE;
    7272          27 :                         opline->op2.constant = zend_add_const_name_literal(
    7273             :                                 CG(active_op_array), resolved_name, 1);
    7274             :                 } else {
    7275        5613 :                         opline->op2.constant = zend_add_const_name_literal(
    7276             :                                 CG(active_op_array), resolved_name, 0);
    7277             :                 }
    7278             :         }
    7279        5708 :         zend_alloc_cache_slot(opline->op2.constant);
    7280             : }
    7281             : /* }}} */
    7282             : 
    7283       10167 : void zend_compile_class_const(znode *result, zend_ast *ast) /* {{{ */
    7284             : {
    7285       10167 :         zend_ast *class_ast = ast->child[0];
    7286       10167 :         zend_ast *const_ast = ast->child[1];
    7287             : 
    7288             :         znode class_node, const_node;
    7289             :         zend_op *opline;
    7290             : 
    7291       10167 :         if (zend_try_compile_const_expr_resolve_class_name(&result->u.constant, class_ast, const_ast, 0)) {
    7292         104 :                 if (Z_TYPE(result->u.constant) == IS_NULL) {
    7293          27 :                         zend_op *opline = zend_emit_op_tmp(result, ZEND_FETCH_CLASS_NAME, NULL, NULL);
    7294          54 :                         opline->extended_value = zend_get_class_fetch_type(zend_ast_get_str(class_ast));
    7295             :                 } else {
    7296          25 :                         result->op_type = IS_CONST;
    7297             :                 }
    7298          52 :                 return;
    7299             :         }
    7300             : 
    7301       10115 :         zend_eval_const_expr(&class_ast);
    7302       10115 :         zend_eval_const_expr(&const_ast);
    7303             : 
    7304       10115 :         if (class_ast->kind == ZEND_AST_ZVAL) {
    7305             :                 zend_string *resolved_name;
    7306             : 
    7307       10110 :                 resolved_name = zend_resolve_class_name_ast(class_ast);
    7308       20218 :                 if (const_ast->kind == ZEND_AST_ZVAL && zend_try_ct_eval_class_const(&result->u.constant, resolved_name, zend_ast_get_str(const_ast))) {
    7309        9990 :                         result->op_type = IS_CONST;
    7310             :                         zend_string_release(resolved_name);
    7311        9990 :                         return;
    7312             :                 }
    7313             :                 zend_string_release(resolved_name);
    7314             :         }
    7315         254 :         if (const_ast->kind == ZEND_AST_ZVAL && zend_string_equals_literal_ci(zend_ast_get_str(const_ast), "class")) {
    7316           0 :                 zend_error_noreturn(E_COMPILE_ERROR,
    7317             :                         "Dynamic class names are not allowed in compile-time ::class fetch");
    7318             :         }
    7319             : 
    7320         124 :         zend_compile_class_ref_ex(&class_node, class_ast, ZEND_FETCH_CLASS_EXCEPTION);
    7321             : 
    7322         123 :         zend_compile_expr(&const_node, const_ast);
    7323             : 
    7324         123 :         opline = zend_emit_op_tmp(result, ZEND_FETCH_CLASS_CONSTANT, NULL, &const_node);
    7325             : 
    7326         123 :         zend_set_class_name_op1(opline, &class_node);
    7327             : 
    7328         123 :         if (opline->op1_type == IS_CONST) {
    7329          95 :                 zend_alloc_cache_slot(opline->op2.constant);
    7330             :         } else {
    7331          28 :                 zend_alloc_polymorphic_cache_slot(opline->op2.constant);
    7332             :         }
    7333             : }
    7334             : /* }}} */
    7335             : 
    7336           0 : void zend_compile_resolve_class_name(znode *result, zend_ast *ast) /* {{{ */
    7337             : {
    7338           0 :         zend_ast *name_ast = ast->child[0];
    7339           0 :         uint32_t fetch_type = zend_get_class_fetch_type(zend_ast_get_str(name_ast));
    7340           0 :         zend_ensure_valid_class_fetch_type(fetch_type);
    7341             : 
    7342           0 :         switch (fetch_type) {
    7343             :                 case ZEND_FETCH_CLASS_SELF:
    7344           0 :                         if (CG(active_class_entry) && zend_is_scope_known()) {
    7345           0 :                                 result->op_type = IS_CONST;
    7346           0 :                                 ZVAL_STR_COPY(&result->u.constant, CG(active_class_entry)->name);
    7347             :                         } else {
    7348           0 :                                 zend_op *opline = zend_emit_op_tmp(result, ZEND_FETCH_CLASS_NAME, NULL, NULL);
    7349           0 :                                 opline->extended_value = fetch_type;
    7350             :                         }
    7351           0 :                         break;
    7352             :                 case ZEND_FETCH_CLASS_STATIC:
    7353             :                 case ZEND_FETCH_CLASS_PARENT:
    7354             :                         {
    7355           0 :                                 zend_op *opline = zend_emit_op_tmp(result, ZEND_FETCH_CLASS_NAME, NULL, NULL);
    7356           0 :                                 opline->extended_value = fetch_type;
    7357             :                         }
    7358           0 :                         break;
    7359             :                 case ZEND_FETCH_CLASS_DEFAULT:
    7360           0 :                         result->op_type = IS_CONST;
    7361           0 :                         ZVAL_STR(&result->u.constant, zend_resolve_class_name_ast(name_ast));
    7362             :                         break;
    7363             :                 EMPTY_SWITCH_DEFAULT_CASE()
    7364             :         }
    7365           0 : }
    7366             : /* }}} */
    7367             : 
    7368       60061 : static zend_op *zend_compile_rope_add(znode *result, uint32_t num, znode *elem_node) /* {{{ */
    7369             : {
    7370       60061 :         zend_op *opline = get_next_op(CG(active_op_array));
    7371             : 
    7372       60061 :         if (num == 0) {
    7373       19231 :                 result->op_type = IS_TMP_VAR;
    7374       19231 :                 result->u.op.var = -1;
    7375       19231 :                 opline->opcode = ZEND_ROPE_INIT;
    7376       19231 :                 SET_UNUSED(opline->op1);
    7377             :         } else {
    7378       40830 :                 opline->opcode = ZEND_ROPE_ADD;
    7379       40830 :                 SET_NODE(opline->op1, result);
    7380             :         }
    7381       60061 :         SET_NODE(opline->op2, elem_node);
    7382       60061 :         SET_NODE(opline->result, result);
    7383       60061 :         opline->extended_value = num;
    7384       60061 :         return opline;
    7385             : }
    7386             : /* }}} */
    7387             : 
    7388       19231 : static void zend_compile_encaps_list(znode *result, zend_ast *ast) /* {{{ */
    7389             : {
    7390             :         uint32_t i, j;
    7391       19231 :         uint32_t rope_init_lineno = -1;
    7392       19231 :         zend_op *opline = NULL, *init_opline;
    7393             :         znode elem_node, last_const_node;
    7394       19231 :         zend_ast_list *list = zend_ast_get_list(ast);
    7395             : 
    7396             :         ZEND_ASSERT(list->children > 0);
    7397             : 
    7398       19231 :         j = 0;
    7399       19231 :         last_const_node.op_type = IS_UNUSED;
    7400       79301 :         for (i = 0; i < list->children; i++) {
    7401       60070 :                 zend_compile_expr(&elem_node, list->child[i]);
    7402             : 
    7403       60070 :                 if (elem_node.op_type == IS_CONST) {
    7404       32963 :                         convert_to_string(&elem_node.u.constant);
    7405             : 
    7406       32963 :                         if (Z_STRLEN(elem_node.u.constant) == 0) {
    7407           9 :                                 zval_ptr_dtor(&elem_node.u.constant);
    7408       32954 :                         } else if (last_const_node.op_type == IS_CONST) {
    7409           0 :                                 concat_function(&last_const_node.u.constant, &last_const_node.u.constant, &elem_node.u.constant);
    7410           0 :                                 zval_ptr_dtor(&elem_node.u.constant);
    7411             :                         } else {
    7412       32954 :                                 last_const_node.op_type = IS_CONST;
    7413       32954 :                                 ZVAL_COPY_VALUE(&last_const_node.u.constant, &elem_node.u.constant);
    7414             :                         }
    7415       32963 :                         continue;
    7416             :                 } else {
    7417       27107 :                         if (j == 0) {
    7418       19231 :                                 rope_init_lineno = get_next_op_number(CG(active_op_array));
    7419             :                         }
    7420       27107 :                         if (last_const_node.op_type == IS_CONST) {
    7421       21693 :                                 zend_compile_rope_add(result, j++, &last_const_node);
    7422       21693 :                                 last_const_node.op_type = IS_UNUSED;
    7423             :                         }
    7424       27107 :                         opline = zend_compile_rope_add(result, j++, &elem_node);
    7425             :                 }
    7426             :         }
    7427             : 
    7428       19231 :         if (j == 0) {
    7429           0 :                 result->op_type = IS_CONST;
    7430           0 :                 if (last_const_node.op_type == IS_CONST) {
    7431           0 :                         ZVAL_COPY_VALUE(&result->u.constant, &last_const_node.u.constant);
    7432             :                 } else {
    7433           0 :                         ZVAL_EMPTY_STRING(&result->u.constant);
    7434             :                         /* empty string */
    7435             :                 }
    7436           0 :                 return;
    7437       19231 :         } else if (last_const_node.op_type == IS_CONST) {
    7438       11261 :                 opline = zend_compile_rope_add(result, j++, &last_const_node);
    7439             :         }
    7440       19231 :         init_opline = CG(active_op_array)->opcodes + rope_init_lineno;
    7441       19231 :         if (j == 1) {
    7442         423 :                 if (opline->op2_type == IS_CONST) {
    7443           0 :                         GET_NODE(result, opline->op2);
    7444           0 :                         MAKE_NOP(opline);
    7445             :                 } else {
    7446         423 :                         opline->opcode = ZEND_CAST;
    7447         423 :                         opline->extended_value = IS_STRING;
    7448         423 :                         opline->op1_type = opline->op2_type;
    7449         423 :                         opline->op1 = opline->op2;
    7450         423 :                         opline->result_type = IS_TMP_VAR;
    7451         423 :                         opline->result.var = get_temporary_variable(CG(active_op_array));
    7452         423 :                         SET_UNUSED(opline->op2);
    7453         423 :                         GET_NODE(result, opline->result);
    7454             :                 }
    7455       18808 :         } else if (j == 2) {
    7456        6051 :                 opline->opcode = ZEND_FAST_CONCAT;
    7457        6051 :                 opline->extended_value = 0;
    7458        6051 :                 opline->op1_type = init_opline->op2_type;
    7459        6051 :                 opline->op1 = init_opline->op2;
    7460        6051 :                 opline->result_type = IS_TMP_VAR;
    7461        6051 :                 opline->result.var = get_temporary_variable(CG(active_op_array));
    7462        6051 :                 MAKE_NOP(init_opline);
    7463        6051 :                 GET_NODE(result, opline->result);
    7464             :         } else {
    7465             :                 uint32_t var;
    7466       12757 :                 uint32_t range = zend_start_live_range(CG(active_op_array), rope_init_lineno);
    7467             : 
    7468       12757 :                 init_opline->extended_value = j;
    7469       12757 :                 opline->opcode = ZEND_ROPE_END;
    7470       12757 :                 opline->result.var = get_temporary_variable(CG(active_op_array));
    7471       12757 :                 var = opline->op1.var = get_temporary_variable(CG(active_op_array));
    7472       12757 :                 GET_NODE(result, opline->result);
    7473             : 
    7474             :                 /* Allocates the necessary number of zval slots to keep the rope */
    7475       12757 :                 i = ((j * sizeof(zend_string*)) + (sizeof(zval) - 1)) / sizeof(zval);
    7476       42524 :                 while (i > 1) {
    7477       17010 :                         get_temporary_variable(CG(active_op_array));
    7478       17010 :                         i--;                    
    7479             :                 }
    7480             : 
    7481       12757 :                 zend_end_live_range(CG(active_op_array), range, opline - CG(active_op_array)->opcodes,
    7482             :                         ZEND_LIVE_ROPE, var);
    7483             : 
    7484             :                 /* Update all the previous opcodes to use the same variable */
    7485       60613 :                 while (opline != init_opline) {
    7486       35099 :                         opline--;
    7487       79144 :                         if (opline->opcode == ZEND_ROPE_ADD &&
    7488       22023 :                             opline->result.var == (uint32_t)-1) {
    7489       22022 :                                 opline->op1.var = var;
    7490       22022 :                                 opline->result.var = var;
    7491       25835 :                         } else if (opline->opcode == ZEND_ROPE_INIT &&
    7492       12758 :                                    opline->result.var == (uint32_t)-1) {
    7493       12757 :                                 opline->result.var = var;
    7494             :                         }
    7495             :                 }
    7496             :         }
    7497             : }
    7498             : /* }}} */
    7499             : 
    7500       11980 : void zend_compile_magic_const(znode *result, zend_ast *ast) /* {{{ */
    7501             : {
    7502             :         zend_op *opline;
    7503             : 
    7504       11980 :         if (zend_try_ct_eval_magic_const(&result->u.constant, ast)) {
    7505       11976 :                 result->op_type = IS_CONST;
    7506       11976 :                 return;
    7507             :         }
    7508             : 
    7509             :         ZEND_ASSERT(ast->attr == T_CLASS_C &&
    7510             :                     CG(active_class_entry) &&
    7511             :                     (CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) != 0);
    7512             : 
    7513           4 :         opline = zend_emit_op_tmp(result, ZEND_FETCH_CLASS_NAME, NULL, NULL);
    7514           4 :         opline->extended_value = ZEND_FETCH_CLASS_SELF;
    7515             : }
    7516             : /* }}} */
    7517             : 
    7518         813 : zend_bool zend_is_allowed_in_const_expr(zend_ast_kind kind) /* {{{ */
    7519             : {
    7520         813 :         return kind == ZEND_AST_ZVAL || kind == ZEND_AST_BINARY_OP
    7521             :                 || kind == ZEND_AST_GREATER || kind == ZEND_AST_GREATER_EQUAL
    7522             :                 || kind == ZEND_AST_AND || kind == ZEND_AST_OR
    7523             :                 || kind == ZEND_AST_UNARY_OP
    7524             :                 || kind == ZEND_AST_UNARY_PLUS || kind == ZEND_AST_UNARY_MINUS
    7525             :                 || kind == ZEND_AST_CONDITIONAL || kind == ZEND_AST_DIM
    7526             :                 || kind == ZEND_AST_ARRAY || kind == ZEND_AST_ARRAY_ELEM
    7527             :                 || kind == ZEND_AST_CONST || kind == ZEND_AST_CLASS_CONST
    7528             :                 || kind == ZEND_AST_MAGIC_CONST || kind == ZEND_AST_COALESCE;
    7529             : }
    7530             : /* }}} */
    7531             : 
    7532         312 : void zend_compile_const_expr_class_const(zend_ast **ast_ptr) /* {{{ */
    7533             : {
    7534         312 :         zend_ast *ast = *ast_ptr;
    7535         312 :         zend_ast *class_ast = ast->child[0];
    7536         312 :         zend_ast *const_ast = ast->child[1];
    7537             :         zend_string *class_name;
    7538         312 :         zend_string *const_name = zend_ast_get_str(const_ast);
    7539             :         zval result;
    7540             :         int fetch_type;
    7541             : 
    7542         312 :         if (class_ast->kind != ZEND_AST_ZVAL) {
    7543           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    7544             :                         "Dynamic class names are not allowed in compile-time class constant references");
    7545             :         }
    7546             : 
    7547         311 :         if (zend_try_compile_const_expr_resolve_class_name(&result, class_ast, const_ast, 1)) {
    7548           0 :                 *ast_ptr = zend_ast_create_zval(&result);
    7549           0 :                 return;
    7550             :         }
    7551             : 
    7552         307 :         class_name = zend_ast_get_str(class_ast);
    7553         307 :         fetch_type = zend_get_class_fetch_type(class_name);
    7554             : 
    7555         307 :         if (ZEND_FETCH_CLASS_STATIC == fetch_type) {
    7556           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    7557             :                         "\"static::\" is not allowed in compile-time constants");
    7558             :         }
    7559             : 
    7560         306 :         if (ZEND_FETCH_CLASS_DEFAULT == fetch_type) {
    7561         268 :                 class_name = zend_resolve_class_name_ast(class_ast);
    7562             :         } else {
    7563             :                 zend_string_addref(class_name);
    7564             :         }
    7565             : 
    7566         306 :         Z_STR(result) = zend_concat3(
    7567             :                 ZSTR_VAL(class_name), ZSTR_LEN(class_name), "::", 2, ZSTR_VAL(const_name), ZSTR_LEN(const_name));
    7568             : 
    7569         306 :         Z_TYPE_INFO(result) = IS_CONSTANT_EX;
    7570         306 :         Z_CONST_FLAGS(result) = fetch_type;
    7571             : 
    7572         306 :         zend_ast_destroy(ast);
    7573             :         zend_string_release(class_name);
    7574             : 
    7575         306 :         *ast_ptr = zend_ast_create_zval(&result);
    7576             : }
    7577             : /* }}} */
    7578             : 
    7579         243 : void zend_compile_const_expr_const(zend_ast **ast_ptr) /* {{{ */
    7580             : {
    7581         243 :         zend_ast *ast = *ast_ptr;
    7582         243 :         zend_ast *name_ast = ast->child[0];
    7583         243 :         zend_string *orig_name = zend_ast_get_str(name_ast);
    7584             :         zend_bool is_fully_qualified;
    7585             : 
    7586             :         zval result, resolved_name;
    7587         243 :         ZVAL_STR(&resolved_name, zend_resolve_const_name(
    7588             :                 orig_name, name_ast->attr, &is_fully_qualified));
    7589             : 
    7590         243 :         if (zend_try_ct_eval_const(&result, Z_STR(resolved_name), is_fully_qualified)) {
    7591           0 :                 zend_string_release(Z_STR(resolved_name));
    7592           0 :                 zend_ast_destroy(ast);
    7593           0 :                 *ast_ptr = zend_ast_create_zval(&result);
    7594           0 :                 return;
    7595             :         }
    7596             : 
    7597         243 :         Z_TYPE_INFO(resolved_name) = IS_CONSTANT_EX;
    7598         243 :         if (!is_fully_qualified) {
    7599         200 :                 Z_CONST_FLAGS(resolved_name) = IS_CONSTANT_UNQUALIFIED;
    7600             :         }
    7601             : 
    7602         243 :         zend_ast_destroy(ast);
    7603         243 :         *ast_ptr = zend_ast_create_zval(&resolved_name);
    7604             : }
    7605             : /* }}} */
    7606             : 
    7607           4 : void zend_compile_const_expr_magic_const(zend_ast **ast_ptr) /* {{{ */
    7608             : {
    7609           4 :         zend_ast *ast = *ast_ptr;
    7610             : 
    7611             :         /* Other cases already resolved by constant folding */
    7612             :         ZEND_ASSERT(ast->attr == T_CLASS_C &&
    7613             :                     CG(active_class_entry) &&
    7614             :                     (CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) != 0);
    7615             : 
    7616             :         {
    7617             :                 zval const_zv;
    7618           4 :                 Z_STR(const_zv) = zend_string_init("__CLASS__", sizeof("__CLASS__")-1, 0);
    7619           4 :                 Z_TYPE_INFO(const_zv) = IS_CONSTANT_EX | (IS_CONSTANT_CLASS << Z_CONST_FLAGS_SHIFT);
    7620             : 
    7621           4 :                 zend_ast_destroy(ast);
    7622           4 :                 *ast_ptr = zend_ast_create_zval(&const_zv);
    7623             :         }
    7624           4 : }
    7625             : /* }}} */
    7626             : 
    7627       21174 : void zend_compile_const_expr(zend_ast **ast_ptr) /* {{{ */
    7628             : {
    7629       21174 :         zend_ast *ast = *ast_ptr;
    7630       21174 :         if (ast == NULL || ast->kind == ZEND_AST_ZVAL) {
    7631       20361 :                 return;
    7632             :         }
    7633             : 
    7634         813 :         if (!zend_is_allowed_in_const_expr(ast->kind)) {
    7635           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Constant expression contains invalid operations");
    7636             :         }
    7637             : 
    7638         812 :         switch (ast->kind) {
    7639             :                 case ZEND_AST_CLASS_CONST:
    7640         312 :                         zend_compile_const_expr_class_const(ast_ptr);
    7641         306 :                         break;
    7642             :                 case ZEND_AST_CONST:
    7643         243 :                         zend_compile_const_expr_const(ast_ptr);
    7644         243 :                         break;
    7645             :                 case ZEND_AST_MAGIC_CONST:
    7646           4 :                         zend_compile_const_expr_magic_const(ast_ptr);
    7647           4 :                         break;
    7648             :                 default:
    7649         253 :                         zend_ast_apply(ast, zend_compile_const_expr);
    7650             :                         break;
    7651             :         }
    7652             : }
    7653             : /* }}} */
    7654             : 
    7655       20724 : void zend_const_expr_to_zval(zval *result, zend_ast *ast) /* {{{ */
    7656             : {
    7657       20724 :         zend_ast *orig_ast = ast;
    7658       20724 :         zend_eval_const_expr(&ast);
    7659       20720 :         zend_compile_const_expr(&ast);
    7660       20713 :         if (ast->kind == ZEND_AST_ZVAL) {
    7661       41178 :                 ZVAL_COPY_VALUE(result, zend_ast_get_zval(ast));
    7662             :         } else {
    7663         124 :                 ZVAL_NEW_AST(result, zend_ast_copy(ast));
    7664             :                 /* destroy the ast here, it might have been replaced */
    7665         124 :                 zend_ast_destroy(ast);
    7666             :         }
    7667             : 
    7668             :         /* Kill this branch of the original AST, as it was already destroyed.
    7669             :          * It would be nice to find a better solution to this problem in the
    7670             :          * future. */
    7671       20713 :         orig_ast->kind = 0;
    7672       20713 : }
    7673             : /* }}} */
    7674             : 
    7675             : /* Same as compile_stmt, but with early binding */
    7676      300436 : void zend_compile_top_stmt(zend_ast *ast) /* {{{ */
    7677             : {
    7678      300436 :         if (!ast) {
    7679       31386 :                 return;
    7680             :         }
    7681             : 
    7682      269050 :         if (ast->kind == ZEND_AST_STMT_LIST) {
    7683       56047 :                 zend_ast_list *list = zend_ast_get_list(ast);
    7684             :                 uint32_t i;
    7685      321705 :                 for (i = 0; i < list->children; ++i) {
    7686      265948 :                         zend_compile_top_stmt(list->child[i]);
    7687             :                 }
    7688       55757 :                 return;
    7689             :         }
    7690             : 
    7691      213003 :         zend_compile_stmt(ast);
    7692             : 
    7693      212773 :         if (ast->kind != ZEND_AST_NAMESPACE && ast->kind != ZEND_AST_HALT_COMPILER) {
    7694      212256 :                 zend_verify_namespace();
    7695             :         }
    7696      212772 :         if (ast->kind == ZEND_AST_FUNC_DECL || ast->kind == ZEND_AST_CLASS) {
    7697       22623 :                 CG(zend_lineno) = ((zend_ast_decl *) ast)->end_lineno;
    7698       22623 :                 zend_do_early_binding();
    7699             :         }
    7700             : }
    7701             : /* }}} */
    7702             : 
    7703      710697 : void zend_compile_stmt(zend_ast *ast) /* {{{ */
    7704             : {
    7705      710697 :         if (!ast) {
    7706         360 :                 return;
    7707             :         }
    7708             : 
    7709      710337 :         CG(zend_lineno) = ast->lineno;
    7710             : 
    7711      710337 :         if ((CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO) && !zend_is_unticked_stmt(ast)) {
    7712           0 :                 zend_do_extended_info();
    7713             :         }
    7714             : 
    7715      710337 :         switch (ast->kind) {
    7716             :                 case ZEND_AST_STMT_LIST:
    7717      162411 :                         zend_compile_stmt_list(ast);
    7718      162314 :                         break;
    7719             :                 case ZEND_AST_GLOBAL:
    7720        5171 :                         zend_compile_global_var(ast);
    7721        5170 :                         break;
    7722             :                 case ZEND_AST_STATIC:
    7723        2128 :                         zend_compile_static_var(ast);
    7724        2127 :                         break;
    7725             :                 case ZEND_AST_UNSET:
    7726        1685 :                         zend_compile_unset(ast);
    7727        1681 :                         break;
    7728             :                 case ZEND_AST_RETURN:
    7729       46331 :                         zend_compile_return(ast);
    7730       46325 :                         break;
    7731             :                 case ZEND_AST_ECHO:
    7732       41060 :                         zend_compile_echo(ast);
    7733       41060 :                         break;
    7734             :                 case ZEND_AST_THROW:
    7735         443 :                         zend_compile_throw(ast);
    7736         443 :                         break;
    7737             :                 case ZEND_AST_BREAK:
    7738             :                 case ZEND_AST_CONTINUE:
    7739        2276 :                         zend_compile_break_continue(ast);
    7740        2271 :                         break;
    7741             :                 case ZEND_AST_GOTO:
    7742          47 :                         zend_compile_goto(ast);
    7743          47 :                         break;
    7744             :                 case ZEND_AST_LABEL:
    7745          48 :                         zend_compile_label(ast);
    7746          47 :                         break;
    7747             :                 case ZEND_AST_WHILE:
    7748        2072 :                         zend_compile_while(ast);
    7749        2071 :                         break;
    7750             :                 case ZEND_AST_DO_WHILE:
    7751         311 :                         zend_compile_do_while(ast);
    7752         311 :                         break;
    7753             :                 case ZEND_AST_FOR:
    7754        2261 :                         zend_compile_for(ast);
    7755        2261 :                         break;
    7756             :                 case ZEND_AST_FOREACH:
    7757       11992 :                         zend_compile_foreach(ast);
    7758       11981 :                         break;
    7759             :                 case ZEND_AST_IF:
    7760       80248 :                         zend_compile_if(ast);
    7761       80248 :                         break;
    7762             :                 case ZEND_AST_SWITCH:
    7763         498 :                         zend_compile_switch(ast);
    7764         497 :                         break;
    7765             :                 case ZEND_AST_TRY:
    7766        2938 :                         zend_compile_try(ast);
    7767        2934 :                         break;
    7768             :                 case ZEND_AST_DECLARE:
    7769          53 :                         zend_compile_declare(ast);
    7770          43 :                         break;
    7771             :                 case ZEND_AST_FUNC_DECL:
    7772             :                 case ZEND_AST_METHOD:
    7773       39335 :                         zend_compile_func_decl(NULL, ast);
    7774       39251 :                         break;
    7775             :                 case ZEND_AST_PROP_DECL:
    7776        2670 :                         zend_compile_prop_decl(ast);
    7777        2665 :                         break;
    7778             :                 case ZEND_AST_CLASS_CONST_DECL:
    7779         371 :                         zend_compile_class_const_decl(ast);
    7780         359 :                         break;
    7781             :                 case ZEND_AST_USE_TRAIT:
    7782         223 :                         zend_compile_use_trait(ast);
    7783         219 :                         break;
    7784             :                 case ZEND_AST_CLASS:
    7785        8096 :                         zend_compile_class_decl(ast);
    7786        8008 :                         break;
    7787             :                 case ZEND_AST_GROUP_USE:
    7788          14 :                         zend_compile_group_use(ast);
    7789          14 :                         break;
    7790             :                 case ZEND_AST_USE:
    7791          94 :                         zend_compile_use(ast);
    7792          82 :                         break;
    7793             :                 case ZEND_AST_CONST_DECL:
    7794         217 :                         zend_compile_const_decl(ast);
    7795         209 :                         break;
    7796             :                 case ZEND_AST_NAMESPACE:
    7797         263 :                         zend_compile_namespace(ast);
    7798         241 :                         break;
    7799             :                 case ZEND_AST_HALT_COMPILER:
    7800         276 :                         zend_compile_halt_compiler(ast);
    7801         276 :                         break;
    7802             :                 default:
    7803             :                 {
    7804             :                         znode result;
    7805      296805 :                         zend_compile_expr(&result, ast);
    7806      296761 :                         zend_do_free(&result);
    7807             :                 }
    7808             :         }
    7809             : 
    7810      709916 :         if (FC(declarables).ticks && !zend_is_unticked_stmt(ast)) {
    7811          31 :                 zend_emit_tick();
    7812             :         }
    7813             : }
    7814             : /* }}} */
    7815             : 
    7816     1682890 : void zend_compile_expr(znode *result, zend_ast *ast) /* {{{ */
    7817             : {
    7818             :         /* CG(zend_lineno) = ast->lineno; */
    7819     1682890 :         CG(zend_lineno) = zend_ast_get_lineno(ast);
    7820             : 
    7821     1682890 :         switch (ast->kind) {
    7822             :                 case ZEND_AST_ZVAL:
    7823     1227918 :                         ZVAL_COPY(&result->u.constant, zend_ast_get_zval(ast));
    7824      613959 :                         result->op_type = IS_CONST;
    7825      613959 :                         return;
    7826             :                 case ZEND_AST_ZNODE:
    7827        5704 :                         *result = *zend_ast_get_znode(ast);
    7828        5704 :                         return;
    7829             :                 case ZEND_AST_VAR:
    7830             :                 case ZEND_AST_DIM:
    7831             :                 case ZEND_AST_PROP:
    7832             :                 case ZEND_AST_STATIC_PROP:
    7833             :                 case ZEND_AST_CALL:
    7834             :                 case ZEND_AST_METHOD_CALL:
    7835             :                 case ZEND_AST_STATIC_CALL:
    7836      500774 :                         zend_compile_var(result, ast, BP_VAR_R);
    7837      500753 :                         return;
    7838             :                 case ZEND_AST_ASSIGN:
    7839      157308 :                         zend_compile_assign(result, ast);
    7840      157291 :                         return;
    7841             :                 case ZEND_AST_ASSIGN_REF:
    7842         488 :                         zend_compile_assign_ref(result, ast);
    7843         486 :                         return;
    7844             :                 case ZEND_AST_NEW:
    7845       15437 :                         zend_compile_new(result, ast);
    7846       15437 :                         return;
    7847             :                 case ZEND_AST_CLONE:
    7848         122 :                         zend_compile_clone(result, ast);
    7849         122 :                         return;
    7850             :                 case ZEND_AST_ASSIGN_OP:
    7851        4148 :                         zend_compile_compound_assign(result, ast);
    7852        4148 :                         return;
    7853             :                 case ZEND_AST_BINARY_OP:
    7854      101748 :                         zend_compile_binary_op(result, ast);
    7855      101748 :                         return;
    7856             :                 case ZEND_AST_GREATER:
    7857             :                 case ZEND_AST_GREATER_EQUAL:
    7858        1582 :                         zend_compile_greater(result, ast);
    7859        1582 :                         return;
    7860             :                 case ZEND_AST_UNARY_OP:
    7861       33626 :                         zend_compile_unary_op(result, ast);
    7862       33626 :                         return;
    7863             :                 case ZEND_AST_UNARY_PLUS:
    7864             :                 case ZEND_AST_UNARY_MINUS:
    7865        3483 :                         zend_compile_unary_pm(result, ast);
    7866        3483 :                         return;
    7867             :                 case ZEND_AST_AND:
    7868             :                 case ZEND_AST_OR:
    7869       13706 :                         zend_compile_short_circuiting(result, ast);
    7870       13706 :                         return;
    7871             :                 case ZEND_AST_POST_INC:
    7872             :                 case ZEND_AST_POST_DEC:
    7873        6134 :                         zend_compile_post_incdec(result, ast);
    7874        6134 :                         return;
    7875             :                 case ZEND_AST_PRE_INC:
    7876             :                 case ZEND_AST_PRE_DEC:
    7877         577 :                         zend_compile_pre_incdec(result, ast);
    7878         576 :                         return;
    7879             :                 case ZEND_AST_CAST:
    7880        6577 :                         zend_compile_cast(result, ast);
    7881        6577 :                         return;
    7882             :                 case ZEND_AST_CONDITIONAL:
    7883       25848 :                         zend_compile_conditional(result, ast);
    7884       25848 :                         return;
    7885             :                 case ZEND_AST_COALESCE:
    7886          27 :                         zend_compile_coalesce(result, ast);
    7887          27 :                         return;
    7888             :                 case ZEND_AST_PRINT:
    7889        3534 :                         zend_compile_print(result, ast);
    7890        3534 :                         return;
    7891             :                 case ZEND_AST_EXIT:
    7892       17371 :                         zend_compile_exit(result, ast);
    7893       17371 :                         return;
    7894             :                 case ZEND_AST_YIELD:
    7895         260 :                         zend_compile_yield(result, ast);
    7896         259 :                         return;
    7897             :                 case ZEND_AST_YIELD_FROM:
    7898          41 :                         zend_compile_yield_from(result, ast);
    7899          40 :                         return;
    7900             :                 case ZEND_AST_INSTANCEOF:
    7901          75 :                         zend_compile_instanceof(result, ast);
    7902          74 :                         return;
    7903             :                 case ZEND_AST_INCLUDE_OR_EVAL:
    7904       13587 :                         zend_compile_include_or_eval(result, ast);
    7905       13587 :                         return;
    7906             :                 case ZEND_AST_ISSET:
    7907             :                 case ZEND_AST_EMPTY:
    7908       13739 :                         zend_compile_isset_or_empty(result, ast);
    7909       13736 :                         return;
    7910             :                 case ZEND_AST_SILENCE:
    7911        7189 :                         zend_compile_silence(result, ast);
    7912        7189 :                         return;
    7913             :                 case ZEND_AST_SHELL_EXEC:
    7914         121 :                         zend_compile_shell_exec(result, ast);
    7915         121 :                         return;
    7916             :                 case ZEND_AST_ARRAY:
    7917       19021 :                         zend_compile_array(result, ast);
    7918       19018 :                         return;
    7919             :                 case ZEND_AST_CONST:
    7920       74745 :                         zend_compile_const(result, ast);
    7921       74745 :                         return;
    7922             :                 case ZEND_AST_CLASS_CONST:
    7923       10167 :                         zend_compile_class_const(result, ast);
    7924       10165 :                         return;
    7925             :                 case ZEND_AST_ENCAPS_LIST:
    7926       19231 :                         zend_compile_encaps_list(result, ast);
    7927       19231 :                         return;
    7928             :                 case ZEND_AST_MAGIC_CONST:
    7929       11980 :                         zend_compile_magic_const(result, ast);
    7930       11980 :                         return;
    7931             :                 case ZEND_AST_CLOSURE:
    7932         581 :                         zend_compile_func_decl(result, ast);
    7933         576 :                         return;
    7934             :                 default:
    7935             :                         ZEND_ASSERT(0 /* not supported */);
    7936             :         }
    7937             : }
    7938             : /* }}} */
    7939             : 
    7940      839270 : void zend_compile_var(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    7941             : {
    7942      839270 :         switch (ast->kind) {
    7943             :                 case ZEND_AST_VAR:
    7944      384288 :                         zend_compile_simple_var(result, ast, type, 0);
    7945      384288 :                         return;
    7946             :                 case ZEND_AST_DIM:
    7947      107833 :                         zend_compile_dim(result, ast, type);
    7948      107827 :                         return;
    7949             :                 case ZEND_AST_PROP:
    7950        6538 :                         zend_compile_prop(result, ast, type);
    7951        6538 :                         return;
    7952             :                 case ZEND_AST_STATIC_PROP:
    7953         429 :                         zend_compile_static_prop(result, ast, type, 0);
    7954         428 :                         return;
    7955             :                 case ZEND_AST_CALL:
    7956      289565 :                         zend_compile_call(result, ast, type);
    7957      289549 :                         return;
    7958             :                 case ZEND_AST_METHOD_CALL:
    7959       38861 :                         zend_compile_method_call(result, ast, type);
    7960       38859 :                         return;
    7961             :                 case ZEND_AST_STATIC_CALL:
    7962       11705 :                         zend_compile_static_call(result, ast, type);
    7963       11705 :                         return;
    7964             :                 case ZEND_AST_ZNODE:
    7965           3 :                         *result = *zend_ast_get_znode(ast);
    7966           3 :                         return;
    7967             :                 default:
    7968          48 :                         if (type == BP_VAR_W || type == BP_VAR_RW || type == BP_VAR_UNSET) {
    7969           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    7970             :                                         "Cannot use temporary expression in write context");
    7971             :                         }
    7972             : 
    7973          47 :                         zend_compile_expr(result, ast);
    7974          47 :                         return;
    7975             :         }
    7976             : }
    7977             : /* }}} */
    7978             : 
    7979      294006 : void zend_delayed_compile_var(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    7980             : {
    7981             :         zend_op *opline;
    7982      294006 :         switch (ast->kind) {
    7983             :                 case ZEND_AST_VAR:
    7984      287392 :                         zend_compile_simple_var(result, ast, type, 1);
    7985      287392 :                         return;
    7986             :                 case ZEND_AST_DIM:
    7987        4726 :                         opline = zend_delayed_compile_dim(result, ast, type);
    7988        4725 :                         zend_adjust_for_fetch_type(opline, type);
    7989        4725 :                         return;
    7990             :                 case ZEND_AST_PROP:
    7991        1349 :                         opline = zend_delayed_compile_prop(result, ast, type);
    7992        1349 :                         zend_adjust_for_fetch_type(opline, type);
    7993        1349 :                         return;
    7994             :                 case ZEND_AST_STATIC_PROP:
    7995         234 :                         zend_compile_static_prop(result, ast, type, 1);
    7996         234 :                         return;
    7997             :                 default:
    7998         305 :                         zend_compile_var(result, ast, type);
    7999         304 :                         return;
    8000             :         }
    8001             : }
    8002             : /* }}} */
    8003             : 
    8004      276736 : void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
    8005             : {
    8006      276736 :         zend_ast *ast = *ast_ptr;
    8007             :         zval result;
    8008             : 
    8009      276736 :         if (!ast) {
    8010       81443 :                 return;
    8011             :         }
    8012             : 
    8013      195293 :         switch (ast->kind) {
    8014             :                 case ZEND_AST_BINARY_OP:
    8015        4255 :                         zend_eval_const_expr(&ast->child[0]);
    8016        4255 :                         zend_eval_const_expr(&ast->child[1]);
    8017        4255 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
    8018        3795 :                                 return;
    8019             :                         }
    8020             : 
    8021        1380 :                         if (!zend_try_ct_eval_binary_op(&result, ast->attr,
    8022             :                                         zend_ast_get_zval(ast->child[0]), zend_ast_get_zval(ast->child[1]))
    8023             :                         ) {
    8024           6 :                                 return;
    8025             :                         }
    8026         452 :                         break;
    8027             :                 case ZEND_AST_GREATER:
    8028             :                 case ZEND_AST_GREATER_EQUAL:
    8029           4 :                         zend_eval_const_expr(&ast->child[0]);
    8030           4 :                         zend_eval_const_expr(&ast->child[1]);
    8031           4 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
    8032           2 :                                 return;
    8033             :                         }
    8034             : 
    8035           6 :                         zend_ct_eval_greater(&result, ast->kind,
    8036             :                                 zend_ast_get_zval(ast->child[0]), zend_ast_get_zval(ast->child[1]));
    8037           2 :                         break;
    8038             :                 case ZEND_AST_AND:
    8039             :                 case ZEND_AST_OR:
    8040             :                 {
    8041             :                         int i;
    8042          24 :                         for (i = 0; i <= 1; i++) {
    8043          17 :                                 zend_eval_const_expr(&ast->child[i]);
    8044          17 :                                 if (ast->child[i]->kind == ZEND_AST_ZVAL) {
    8045          24 :                                         if (zend_is_true(zend_ast_get_zval(ast->child[i])) == (ast->kind == ZEND_AST_OR)) {
    8046           2 :                                                 ZVAL_BOOL(&result, ast->kind == ZEND_AST_OR);
    8047           2 :                                                 return;
    8048             :                                         }
    8049             :                                 }
    8050             :                         }
    8051             : 
    8052           7 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
    8053           5 :                                 return;
    8054             :                         }
    8055             : 
    8056           2 :                         if (ast->kind == ZEND_AST_OR) {
    8057           3 :                                 ZVAL_BOOL(&result, zend_is_true(zend_ast_get_zval(ast->child[0])) || zend_is_true(zend_ast_get_zval(ast->child[1])));
    8058             :                         } else {
    8059           3 :                                 ZVAL_BOOL(&result, zend_is_true(zend_ast_get_zval(ast->child[0])) && zend_is_true(zend_ast_get_zval(ast->child[1])));
    8060             :                         }
    8061           2 :                         break;
    8062             :                 }
    8063             :                 case ZEND_AST_UNARY_OP:
    8064           3 :                         zend_eval_const_expr(&ast->child[0]);
    8065           3 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL) {
    8066           1 :                                 return;
    8067             :                         }
    8068             : 
    8069           4 :                         zend_ct_eval_unary_op(&result, ast->attr, zend_ast_get_zval(ast->child[0]));
    8070           2 :                         break;
    8071             :                 case ZEND_AST_UNARY_PLUS:
    8072             :                 case ZEND_AST_UNARY_MINUS:
    8073        3478 :                         zend_eval_const_expr(&ast->child[0]);
    8074        3478 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL) {
    8075           4 :                                 return;
    8076             :                         }
    8077             : 
    8078        6948 :                         if (!zend_try_ct_eval_unary_pm(&result, ast->kind, zend_ast_get_zval(ast->child[0]))) {
    8079           0 :                                 return;
    8080             :                         }
    8081        3474 :                         break;
    8082             :                 case ZEND_AST_COALESCE:
    8083             :                         /* Set isset fetch indicator here, opcache disallows runtime altering of the AST */
    8084          24 :                         if (ast->child[0]->kind == ZEND_AST_DIM) {
    8085          13 :                                 ast->child[0]->attr = ZEND_DIM_IS;
    8086             :                         }
    8087          24 :                         zend_eval_const_expr(&ast->child[0]);
    8088             : 
    8089          23 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL) {
    8090             :                                 /* ensure everything was compile-time evaluated at least once */
    8091          12 :                                 zend_eval_const_expr(&ast->child[1]);
    8092          12 :                                 return;
    8093             :                         }
    8094             : 
    8095          22 :                         if (Z_TYPE_P(zend_ast_get_zval(ast->child[0])) == IS_NULL) {
    8096          10 :                                 zend_eval_const_expr(&ast->child[1]);
    8097          10 :                                 *ast_ptr = ast->child[1];
    8098          10 :                                 ast->child[1] = NULL;
    8099          10 :                                 zend_ast_destroy(ast);
    8100             :                         } else {
    8101           1 :                                 *ast_ptr = ast->child[0];
    8102           1 :                                 ast->child[0] = NULL;
    8103           1 :                                 zend_ast_destroy(ast);
    8104             :                         }
    8105          11 :                         return;
    8106             :                 case ZEND_AST_CONDITIONAL:
    8107             :                 {
    8108             :                         zend_ast **child, *child_ast;
    8109          35 :                         zend_eval_const_expr(&ast->child[0]);
    8110          35 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL) {
    8111             :                                 /* ensure everything was compile-time evaluated at least once */
    8112          32 :                                 if (ast->child[1]) {
    8113          29 :                                         zend_eval_const_expr(&ast->child[1]);
    8114             :                                 }
    8115          32 :                                 zend_eval_const_expr(&ast->child[2]);
    8116          32 :                                 return;
    8117             :                         }
    8118             : 
    8119           6 :                         child = &ast->child[2 - zend_is_true(zend_ast_get_zval(ast->child[0]))];
    8120           3 :                         if (*child == NULL) {
    8121           1 :                                 child--;
    8122             :                         }
    8123           3 :                         child_ast = *child;
    8124           3 :                         *child = NULL;
    8125           3 :                         zend_ast_destroy(ast);
    8126           3 :                         *ast_ptr = child_ast;
    8127           3 :                         zend_eval_const_expr(ast_ptr);
    8128           3 :                         return;
    8129             :                 }
    8130             :                 case ZEND_AST_DIM:
    8131             :                 {
    8132             :                         /* constant expression should be always read context ... */
    8133             :                         zval *container, *dim;
    8134             : 
    8135         119 :                         if (ast->child[1] == NULL) {
    8136           3 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use [] for reading");
    8137             :                         }
    8138             : 
    8139             :                         /* Set isset fetch indicator here, opcache disallows runtime altering of the AST */
    8140         116 :                         if (ast->attr == ZEND_DIM_IS && ast->child[0]->kind == ZEND_AST_DIM) {
    8141          21 :                                 ast->child[0]->attr = ZEND_DIM_IS;
    8142             :                         }
    8143             : 
    8144         116 :                         zend_eval_const_expr(&ast->child[0]);
    8145         116 :                         zend_eval_const_expr(&ast->child[1]);
    8146         116 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
    8147         112 :                                 return;
    8148             :                         }
    8149             : 
    8150           8 :                         container = zend_ast_get_zval(ast->child[0]);
    8151           8 :                         dim = zend_ast_get_zval(ast->child[1]);
    8152             : 
    8153           4 :                         if (Z_TYPE_P(container) == IS_ARRAY) {
    8154             :                                 zval *el;
    8155           4 :                                 if (Z_TYPE_P(dim) == IS_LONG) {
    8156           2 :                                         el = zend_hash_index_find(Z_ARR_P(container), Z_LVAL_P(dim));
    8157           2 :                                         if (el) {
    8158           2 :                                                 ZVAL_COPY(&result, el);
    8159             :                                         } else {
    8160           0 :                                                 return;
    8161             :                                         }
    8162           2 :                                 } else if (Z_TYPE_P(dim) == IS_STRING) {
    8163           4 :                                         el = zend_symtable_find(Z_ARR_P(container), Z_STR_P(dim));
    8164           2 :                                         if (el) {
    8165           2 :                                                 ZVAL_COPY(&result, el);
    8166             :                                         } else {
    8167           0 :                                                 return;
    8168             :                                         }
    8169             :                                 } else {
    8170           0 :                                         return; /* warning... handle at runtime */
    8171             :                                 }
    8172           0 :                         } else if (Z_TYPE_P(container) == IS_STRING) {
    8173             :                                 zend_long offset;
    8174             :                                 zend_uchar c;
    8175           0 :                                 if (Z_TYPE_P(dim) == IS_LONG) {
    8176           0 :                                         offset = Z_LVAL_P(dim);
    8177           0 :                                 } else if (Z_TYPE_P(dim) != IS_STRING || is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, 1) != IS_LONG) {
    8178           0 :                                         return;
    8179             :                                 }
    8180           0 :                                 if (offset < 0 || (size_t)offset >= Z_STRLEN_P(container)) {
    8181           0 :                                         return;
    8182             :                                 }
    8183           0 :                                 c = (zend_uchar) Z_STRVAL_P(container)[offset];
    8184           0 :                                 if (CG(one_char_string)[c]) {
    8185           0 :                                         ZVAL_INTERNED_STR(&result, CG(one_char_string)[c]);
    8186             :                                 } else {
    8187           0 :                                         ZVAL_NEW_STR(&result, zend_string_init((char *) &c, 1, 0));
    8188             :                                 }
    8189           0 :                         } else if (Z_TYPE_P(container) <= IS_FALSE) {
    8190           0 :                                 ZVAL_NULL(&result);
    8191             :                         } else {
    8192           0 :                                 return;
    8193             :                         }
    8194           4 :                         break;
    8195             :                 }
    8196             :                 case ZEND_AST_ARRAY:
    8197       11805 :                         if (!zend_try_ct_eval_array(&result, ast)) {
    8198        1100 :                                 return;
    8199             :                         }
    8200       10705 :                         break;
    8201             :                 case ZEND_AST_MAGIC_CONST:
    8202         189 :                         if (!zend_try_ct_eval_magic_const(&result, ast)) {
    8203           2 :                                 return;
    8204             :                         }
    8205         187 :                         break;
    8206             :                 case ZEND_AST_CONST:
    8207             :                 {
    8208       16875 :                         zend_ast *name_ast = ast->child[0];
    8209             :                         zend_bool is_fully_qualified;
    8210       33750 :                         zend_string *resolved_name = zend_resolve_const_name(
    8211       33750 :                                 zend_ast_get_str(name_ast), name_ast->attr, &is_fully_qualified);
    8212             : 
    8213       16875 :                         if (!zend_try_ct_eval_const(&result, resolved_name, is_fully_qualified)) {
    8214             :                                 zend_string_release(resolved_name);
    8215        1735 :                                 return;
    8216             :                         }
    8217             : 
    8218             :                         zend_string_release(resolved_name);
    8219       15140 :                         break;
    8220             :                 }
    8221             :                 case ZEND_AST_CLASS_CONST:
    8222             :                 {
    8223         838 :                         zend_ast *class_ast = ast->child[0];
    8224         838 :                         zend_ast *name_ast = ast->child[1];
    8225             :                         zend_string *resolved_name;
    8226             : 
    8227         838 :                         if (zend_try_compile_const_expr_resolve_class_name(&result, class_ast, name_ast, 0)) {
    8228          18 :                                 if (Z_TYPE(result) == IS_NULL) {
    8229          14 :                                         if (zend_get_class_fetch_type(zend_ast_get_str(class_ast)) == ZEND_FETCH_CLASS_SELF) {
    8230           2 :                                                 zend_ast_destroy(ast);
    8231           2 :                                                 *ast_ptr = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_CLASS_C);
    8232             :                                         }
    8233           7 :                                         return;
    8234             :                                 }
    8235          11 :                                 break;
    8236             :                         }
    8237             : 
    8238         820 :                         zend_eval_const_expr(&class_ast);
    8239         820 :                         zend_eval_const_expr(&name_ast);
    8240             : 
    8241        1698 :                         if (name_ast->kind == ZEND_AST_ZVAL && zend_string_equals_literal_ci(zend_ast_get_str(name_ast), "class")) {
    8242           0 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    8243             :                                         "Dynamic class names are not allowed in compile-time ::class fetch");
    8244             :                         }
    8245             : 
    8246         820 :                         if (class_ast->kind != ZEND_AST_ZVAL || name_ast->kind != ZEND_AST_ZVAL) {
    8247           1 :                                 return;
    8248             :                         }
    8249             : 
    8250         819 :                         resolved_name = zend_resolve_class_name_ast(class_ast);
    8251             : 
    8252        1638 :                         if (!zend_try_ct_eval_class_const(&result, resolved_name, zend_ast_get_str(name_ast))) {
    8253             :                                 zend_string_release(resolved_name);
    8254         363 :                                 return;
    8255             :                         }
    8256             : 
    8257             :                         zend_string_release(resolved_name);
    8258         456 :                         break;
    8259             :                 }
    8260             : 
    8261             :                 default:
    8262      157659 :                         return;
    8263             :         }
    8264             : 
    8265       30435 :         zend_ast_destroy(ast);
    8266       30435 :         *ast_ptr = zend_ast_create_zval(&result);
    8267             : }
    8268             : /* }}} */
    8269             : 
    8270             : /*
    8271             :  * Local variables:
    8272             :  * tab-width: 4
    8273             :  * c-basic-offset: 4
    8274             :  * indent-tabs-mode: t
    8275             :  * End:
    8276             :  */

Generated by: LCOV version 1.10

Generated at Tue, 26 Jul 2016 17:07:31 +0000 (2 days ago)

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