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_API.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 1618 2117 76.4 %
Date: 2016-08-28 Functions: 133 180 73.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             :    |          Andrei Zmievski <andrei@php.net>                            |
      18             :    |          Dmitry Stogov <dmitry@zend.com>                             |
      19             :    +----------------------------------------------------------------------+
      20             : */
      21             : 
      22             : /* $Id$ */
      23             : 
      24             : #include "zend.h"
      25             : #include "zend_execute.h"
      26             : #include "zend_API.h"
      27             : #include "zend_modules.h"
      28             : #include "zend_extensions.h"
      29             : #include "zend_constants.h"
      30             : #include "zend_interfaces.h"
      31             : #include "zend_exceptions.h"
      32             : #include "zend_closures.h"
      33             : #include "zend_inheritance.h"
      34             : 
      35             : #ifdef HAVE_STDARG_H
      36             : #include <stdarg.h>
      37             : #endif
      38             : 
      39             : /* these variables are true statics/globals, and have to be mutex'ed on every access */
      40             : ZEND_API HashTable module_registry;
      41             : 
      42             : static zend_module_entry **module_request_startup_handlers;
      43             : static zend_module_entry **module_request_shutdown_handlers;
      44             : static zend_module_entry **module_post_deactivate_handlers;
      45             : 
      46             : static zend_class_entry  **class_cleanup_handlers;
      47             : 
      48             : /* this function doesn't check for too many parameters */
      49           0 : ZEND_API int zend_get_parameters(int ht, int param_count, ...) /* {{{ */
      50             : {
      51             :         int arg_count;
      52             :         va_list ptr;
      53             :         zval **param, *param_ptr;
      54             : 
      55           0 :         param_ptr = ZEND_CALL_ARG(EG(current_execute_data), 1);
      56           0 :         arg_count = ZEND_CALL_NUM_ARGS(EG(current_execute_data));
      57             : 
      58           0 :         if (param_count>arg_count) {
      59           0 :                 return FAILURE;
      60             :         }
      61             : 
      62           0 :         va_start(ptr, param_count);
      63             : 
      64           0 :         while (param_count-->0) {
      65           0 :                 param = va_arg(ptr, zval **);
      66           0 :                 if (!Z_ISREF_P(param_ptr) && Z_REFCOUNT_P(param_ptr) > 1) {
      67             :                         zval new_tmp;
      68             : 
      69           0 :                         ZVAL_DUP(&new_tmp, param_ptr);
      70             :                         Z_DELREF_P(param_ptr);
      71           0 :                         ZVAL_COPY_VALUE(param_ptr, &new_tmp);
      72             :                 }
      73           0 :                 *param = param_ptr;
      74           0 :                 param_ptr++;
      75             :         }
      76           0 :         va_end(ptr);
      77             : 
      78           0 :         return SUCCESS;
      79             : }
      80             : /* }}} */
      81             : 
      82             : /* Zend-optimized Extended functions */
      83             : /* this function doesn't check for too many parameters */
      84           0 : ZEND_API int zend_get_parameters_ex(int param_count, ...) /* {{{ */
      85             : {
      86             :         int arg_count;
      87             :         va_list ptr;
      88             :         zval **param, *param_ptr;
      89             : 
      90           0 :         param_ptr = ZEND_CALL_ARG(EG(current_execute_data), 1);
      91           0 :         arg_count = ZEND_CALL_NUM_ARGS(EG(current_execute_data));
      92             : 
      93           0 :         if (param_count>arg_count) {
      94           0 :                 return FAILURE;
      95             :         }
      96             : 
      97           0 :         va_start(ptr, param_count);
      98           0 :         while (param_count-->0) {
      99           0 :                 param = va_arg(ptr, zval **);
     100           0 :                 *param = param_ptr;
     101           0 :                 param_ptr++;
     102             :         }
     103           0 :         va_end(ptr);
     104             : 
     105           0 :         return SUCCESS;
     106             : }
     107             : /* }}} */
     108             : 
     109       21841 : ZEND_API int _zend_get_parameters_array_ex(int param_count, zval *argument_array) /* {{{ */
     110             : {
     111             :         zval *param_ptr;
     112             :         int arg_count;
     113             : 
     114       21841 :         param_ptr = ZEND_CALL_ARG(EG(current_execute_data), 1);
     115       21841 :         arg_count = ZEND_CALL_NUM_ARGS(EG(current_execute_data));
     116             : 
     117       21841 :         if (param_count>arg_count) {
     118           0 :                 return FAILURE;
     119             :         }
     120             : 
     121      261964 :         while (param_count-->0) {
     122      218282 :                 ZVAL_COPY_VALUE(argument_array, param_ptr);
     123      218282 :                 argument_array++;
     124      218282 :                 param_ptr++;
     125             :         }
     126             : 
     127       21841 :         return SUCCESS;
     128             : }
     129             : /* }}} */
     130             : 
     131           2 : ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array) /* {{{ */
     132             : {
     133             :         zval *param_ptr;
     134             :         int arg_count;
     135             : 
     136           2 :         param_ptr = ZEND_CALL_ARG(EG(current_execute_data), 1);
     137           2 :         arg_count = ZEND_CALL_NUM_ARGS(EG(current_execute_data));
     138             : 
     139           2 :         if (param_count>arg_count) {
     140           0 :                 return FAILURE;
     141             :         }
     142             : 
     143           6 :         while (param_count-->0) {
     144           2 :                 if (Z_REFCOUNTED_P(param_ptr)) {
     145             :                         Z_ADDREF_P(param_ptr);
     146             :                 }
     147           2 :                 zend_hash_next_index_insert_new(Z_ARRVAL_P(argument_array), param_ptr);
     148           2 :                 param_ptr++;
     149             :         }
     150             : 
     151           2 :         return SUCCESS;
     152             : }
     153             : /* }}} */
     154             : 
     155          31 : ZEND_API ZEND_COLD void zend_wrong_param_count(void) /* {{{ */
     156             : {
     157             :         const char *space;
     158          31 :         const char *class_name = get_active_class_name(&space);
     159             : 
     160          31 :         zend_internal_type_error(ZEND_ARG_USES_STRICT_TYPES(), "Wrong parameter count for %s%s%s()", class_name, space, get_active_function_name());
     161          31 : }
     162             : /* }}} */
     163             : 
     164             : /* Argument parsing API -- andrei */
     165        8278 : ZEND_API char *zend_get_type_by_const(int type) /* {{{ */
     166             : {
     167        8278 :         switch(type) {
     168             :                 case IS_FALSE:
     169             :                 case IS_TRUE:
     170             :                 case _IS_BOOL:
     171         699 :                         return "boolean";
     172             :                 case IS_LONG:
     173         779 :                         return "integer";
     174             :                 case IS_DOUBLE:
     175         705 :                         return "float";
     176             :                 case IS_STRING:
     177        2176 :                         return "string";
     178             :                 case IS_OBJECT:
     179         767 :                         return "object";
     180             :                 case IS_RESOURCE:
     181         439 :                         return "resource";
     182             :                 case IS_NULL:
     183         652 :                         return "null";
     184             :                 case IS_CALLABLE:
     185           0 :                         return "callable";
     186             :                 case IS_ITERABLE:
     187           2 :                         return "iterable";
     188             :                 case IS_ARRAY:
     189        2059 :                         return "array";
     190             :                 case IS_VOID:
     191           0 :                         return "void";
     192             :                 default:
     193           0 :                         return "unknown";
     194             :         }
     195             : }
     196             : /* }}} */
     197             : 
     198        7989 : ZEND_API char *zend_zval_type_name(const zval *arg) /* {{{ */
     199             : {
     200        7989 :         ZVAL_DEREF(arg);
     201        7989 :         return zend_get_type_by_const(Z_TYPE_P(arg));
     202             : }
     203             : /* }}} */
     204             : 
     205             : #ifdef FAST_ZPP
     206         422 : ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(int num_args, int min_num_args, int max_num_args) /* {{{ */
     207             : {
     208         422 :         zend_function *active_function = EG(current_execute_data)->func;
     209         422 :         const char *class_name = active_function->common.scope ? ZSTR_VAL(active_function->common.scope->name) : "";
     210             : 
     211        1266 :         zend_internal_type_error(ZEND_ARG_USES_STRICT_TYPES(), "%s%s%s() expects %s %d parameter%s, %d given",
     212             :                 class_name, \
     213         422 :                 class_name[0] ? "::" : "", \
     214         422 :                 ZSTR_VAL(active_function->common.function_name),
     215             :                 min_num_args == max_num_args ? "exactly" : num_args < min_num_args ? "at least" : "at most",
     216             :                 num_args < min_num_args ? min_num_args : max_num_args,
     217             :                 (num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
     218             :                 num_args);
     219         422 : }
     220             : /* }}} */
     221             : 
     222        1162 : ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(int num, zend_expected_type expected_type, zval *arg) /* {{{ */
     223             : {
     224             :         const char *space;
     225        1162 :         const char *class_name = get_active_class_name(&space);
     226             :         static const char * const expected_error[] = {
     227             :                 Z_EXPECTED_TYPES(Z_EXPECTED_TYPE_STR)
     228             :                 NULL
     229             :         };
     230             : 
     231        1162 :         zend_internal_type_error(ZEND_ARG_USES_STRICT_TYPES(), "%s%s%s() expects parameter %d to be %s, %s given",
     232             :                 class_name, space, get_active_function_name(), num, expected_error[expected_type], zend_zval_type_name(arg));
     233        1162 : }
     234             : /* }}} */
     235             : 
     236           0 : ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(int num, char *name, zval *arg) /* {{{ */
     237             : {
     238             :         const char *space;
     239           0 :         const char *class_name = get_active_class_name(&space);
     240             : 
     241           0 :         zend_internal_type_error(ZEND_ARG_USES_STRICT_TYPES(), "%s%s%s() expects parameter %d to be %s, %s given",
     242             :                 class_name, space, get_active_function_name(), num, name, zend_zval_type_name(arg));
     243           0 : }
     244             : /* }}} */
     245             : 
     246         109 : ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(int severity, int num, char *error) /* {{{ */
     247             : {
     248             :         const char *space;
     249         109 :         const char *class_name = get_active_class_name(&space);
     250             : 
     251         109 :         if (severity == E_WARNING) {
     252         106 :                 zend_internal_type_error(ZEND_ARG_USES_STRICT_TYPES(), "%s%s%s() expects parameter %d to be a valid callback, %s",
     253             :                         class_name, space, get_active_function_name(), num, error);
     254           3 :         } else if (severity == E_ERROR) {
     255           0 :                 zend_throw_error(zend_ce_type_error, "%s%s%s() expects parameter %d to be a valid callback, %s",
     256             :                         class_name, space, get_active_function_name(), num, error);
     257             :         } else {
     258           3 :                 zend_error(severity, "%s%s%s() expects parameter %d to be a valid callback, %s",
     259             :                         class_name, space, get_active_function_name(), num, error);
     260             :         }
     261         109 :         efree(error);
     262         109 : }
     263             : /* }}} */
     264             : 
     265           4 : ZEND_API int ZEND_FASTCALL zend_parse_arg_class(zval *arg, zend_class_entry **pce, int num, int check_null) /* {{{ */
     266             : {
     267           4 :         zend_class_entry *ce_base = *pce;
     268             : 
     269           4 :         if (check_null && Z_TYPE_P(arg) == IS_NULL) {
     270           0 :                 *pce = NULL;
     271           0 :                 return 1;
     272             :         }
     273           4 :         convert_to_string_ex(arg);
     274           4 :         *pce = zend_lookup_class(Z_STR_P(arg));
     275           4 :         if (ce_base) {
     276           4 :                 if ((!*pce || !instanceof_function(*pce, ce_base))) {
     277             :                         const char *space;
     278           2 :                         const char *class_name = get_active_class_name(&space);
     279             : 
     280           4 :                         zend_internal_type_error(ZEND_ARG_USES_STRICT_TYPES(), "%s%s%s() expects parameter %d to be a class name derived from %s, '%s' given",
     281             :                                 class_name, space, get_active_function_name(), num,
     282           4 :                                 ZSTR_VAL(ce_base->name), Z_STRVAL_P(arg));
     283           2 :                         *pce = NULL;
     284           2 :                         return 0;
     285             :                 }
     286             :         }
     287           2 :         if (!*pce) {
     288             :                 const char *space;
     289           0 :                 const char *class_name = get_active_class_name(&space);
     290             : 
     291           0 :                 zend_internal_type_error(ZEND_ARG_USES_STRICT_TYPES(), "%s%s%s() expects parameter %d to be a valid class name, '%s' given",
     292             :                         class_name, space, get_active_function_name(), num,
     293           0 :                         Z_STRVAL_P(arg));
     294           0 :                 return 0;
     295             :         }
     296           2 :         return 1;
     297             : }
     298             : /* }}} */
     299             : #endif
     300             : 
     301        1291 : ZEND_API int ZEND_FASTCALL zend_parse_arg_bool_weak(zval *arg, zend_bool *dest) /* {{{ */
     302             : {
     303        1291 :         if (EXPECTED(Z_TYPE_P(arg) <= IS_STRING)) {
     304        1130 :                 *dest = zend_is_true(arg);
     305             :         } else {
     306         161 :                 return 0;
     307             :         }
     308        1130 :         return 1;
     309             : }
     310             : /* }}} */
     311             : 
     312        1264 : ZEND_API int ZEND_FASTCALL zend_parse_arg_bool_slow(zval *arg, zend_bool *dest) /* {{{ */
     313             : {
     314        1264 :         if (UNEXPECTED(ZEND_ARG_USES_STRICT_TYPES())) {
     315           0 :                 return 0;
     316             :         }
     317        1264 :         return zend_parse_arg_bool_weak(arg, dest);
     318             : }
     319             : /* }}} */
     320             : 
     321       37858 : ZEND_API int ZEND_FASTCALL zend_parse_arg_long_weak(zval *arg, zend_long *dest) /* {{{ */
     322             : {
     323       37858 :         if (EXPECTED(Z_TYPE_P(arg) == IS_DOUBLE)) {
     324        3005 :                 if (UNEXPECTED(zend_isnan(Z_DVAL_P(arg)))) {
     325           3 :                         return 0;
     326             :                 }
     327        3002 :                 if (UNEXPECTED(!ZEND_DOUBLE_FITS_LONG(Z_DVAL_P(arg)))) {
     328           9 :                         return 0;
     329             :                 } else {
     330        5986 :                         *dest = zend_dval_to_lval(Z_DVAL_P(arg));
     331             :                 }
     332       34853 :         } else if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
     333             :                 double d;
     334             :                 int type;
     335             : 
     336       31749 :                 if (UNEXPECTED((type = is_numeric_str_function(Z_STR_P(arg), dest, &d)) != IS_LONG)) {
     337       31436 :                         if (EXPECTED(type != 0)) {
     338         224 :                                 if (UNEXPECTED(zend_isnan(d))) {
     339           0 :                                         return 0;
     340             :                                 }
     341         224 :                                 if (UNEXPECTED(!ZEND_DOUBLE_FITS_LONG(d))) {
     342           0 :                                         return 0;
     343             :                                 } else {
     344         448 :                                         *dest = zend_dval_to_lval(d);
     345             :                                 }
     346             :                         } else {
     347       31212 :                                 return 0;
     348             :                         }
     349             :                 }
     350        3104 :         } else if (EXPECTED(Z_TYPE_P(arg) < IS_TRUE)) {
     351        1645 :                 *dest = 0;
     352        1459 :         } else if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) {
     353         571 :                 *dest = 1;
     354             :         } else {
     355         888 :                 return 0;
     356             :         }
     357        5746 :         return 1;
     358             : }
     359             : /* }}} */
     360             : 
     361       37823 : ZEND_API int ZEND_FASTCALL zend_parse_arg_long_slow(zval *arg, zend_long *dest) /* {{{ */
     362             : {
     363       37823 :         if (UNEXPECTED(ZEND_ARG_USES_STRICT_TYPES())) {
     364           0 :                 return 0;
     365             :         }
     366       37823 :         return zend_parse_arg_long_weak(arg, dest);
     367             : }
     368             : /* }}} */
     369             : 
     370           0 : ZEND_API int ZEND_FASTCALL zend_parse_arg_long_cap_weak(zval *arg, zend_long *dest) /* {{{ */
     371             : {
     372           0 :         if (EXPECTED(Z_TYPE_P(arg) == IS_DOUBLE)) {
     373           0 :                 if (UNEXPECTED(zend_isnan(Z_DVAL_P(arg)))) {
     374           0 :                         return 0;
     375             :                 }
     376           0 :                 *dest = zend_dval_to_lval_cap(Z_DVAL_P(arg));
     377           0 :         } else if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
     378             :                 double d;
     379             :                 int type;
     380             : 
     381           0 :                 if (UNEXPECTED((type = is_numeric_str_function(Z_STR_P(arg), dest, &d)) != IS_LONG)) {
     382           0 :                         if (EXPECTED(type != 0)) {
     383           0 :                                 if (UNEXPECTED(zend_isnan(d))) {
     384           0 :                                         return 0;
     385             :                                 }
     386           0 :                                 *dest = zend_dval_to_lval_cap(d);
     387             :                         } else {
     388           0 :                                 return 0;
     389             :                         }
     390             :                 }
     391           0 :         } else if (EXPECTED(Z_TYPE_P(arg) < IS_TRUE)) {
     392           0 :                 *dest = 0;
     393           0 :         } else if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) {
     394           0 :                 *dest = 1;
     395             :         } else {
     396           0 :                 return 0;
     397             :         }
     398           0 :         return 1;
     399             : }
     400             : /* }}} */
     401             : 
     402           0 : ZEND_API int ZEND_FASTCALL zend_parse_arg_long_cap_slow(zval *arg, zend_long *dest) /* {{{ */
     403             : {
     404           0 :         if (UNEXPECTED(ZEND_ARG_USES_STRICT_TYPES())) {
     405           0 :                 return 0;
     406             :         }
     407           0 :         return zend_parse_arg_long_cap_weak(arg, dest);
     408             : }
     409             : /* }}} */
     410             : 
     411      953668 : ZEND_API int ZEND_FASTCALL zend_parse_arg_double_weak(zval *arg, double *dest) /* {{{ */
     412             : {
     413      953668 :         if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
     414      952156 :                 *dest = (double)Z_LVAL_P(arg);
     415        1512 :         } else if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
     416             :                 zend_long l;
     417             :                 int type;
     418             : 
     419         647 :                 if (UNEXPECTED((type = is_numeric_str_function(Z_STR_P(arg), &l, dest)) != IS_DOUBLE)) {
     420         427 :                         if (EXPECTED(type != 0)) {
     421         174 :                                 *dest = (double)(l);
     422             :                         } else {
     423         253 :                                 return 0;
     424             :                         }
     425             :                 }
     426         865 :         } else if (EXPECTED(Z_TYPE_P(arg) < IS_TRUE)) {
     427         466 :                 *dest = 0.0;
     428         399 :         } else if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) {
     429         193 :                 *dest = 1.0;
     430             :         } else {
     431         206 :                 return 0;
     432             :         }
     433      953209 :         return 1;
     434             : }
     435             : /* }}} */
     436             : 
     437      953638 : ZEND_API int ZEND_FASTCALL zend_parse_arg_double_slow(zval *arg, double *dest) /* {{{ */
     438             : {
     439      953638 :         if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
     440             :                 /* SSTH Exception: IS_LONG may be accepted instead as IS_DOUBLE */
     441      952146 :                 *dest = (double)Z_LVAL_P(arg);
     442        1492 :         } else if (UNEXPECTED(ZEND_ARG_USES_STRICT_TYPES())) {
     443           0 :                 return 0;
     444             :         }
     445      953638 :         return zend_parse_arg_double_weak(arg, dest);
     446             : }
     447             : /* }}} */
     448             : 
     449      257227 : ZEND_API int ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **dest) /* {{{ */
     450             : {
     451      257227 :         if (EXPECTED(Z_TYPE_P(arg) < IS_STRING)) {
     452       55580 :                 convert_to_string(arg);
     453       55580 :                 *dest = Z_STR_P(arg);
     454      201647 :         } else if (UNEXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
     455      200502 :                 if (Z_OBJ_HANDLER_P(arg, cast_object)) {
     456             :                         zval obj;
     457      200502 :                         if (Z_OBJ_HANDLER_P(arg, cast_object)(arg, &obj, IS_STRING) == SUCCESS) {
     458      200308 :                                 zval_ptr_dtor(arg);
     459      200308 :                                 ZVAL_COPY_VALUE(arg, &obj);
     460      200308 :                                 *dest = Z_STR_P(arg);
     461      200308 :                                 return 1;
     462             :                         }
     463           0 :                 } else if (Z_OBJ_HANDLER_P(arg, get)) {
     464             :                         zval rv;
     465           0 :                         zval *z = Z_OBJ_HANDLER_P(arg, get)(arg, &rv);
     466             : 
     467             :                         Z_ADDREF_P(z);
     468           0 :                         if (Z_TYPE_P(z) != IS_OBJECT) {
     469             :                                 zval_dtor(arg);
     470           0 :                                 ZVAL_NULL(arg);
     471           0 :                                 if (!zend_make_printable_zval(z, arg)) {
     472           0 :                                         ZVAL_COPY_VALUE(arg, z);
     473             :                                 }
     474           0 :                                 *dest = Z_STR_P(arg);
     475           0 :                                 return 1;
     476             :                         }
     477           0 :                         zval_ptr_dtor(z);
     478             :                 }
     479         194 :                 return 0;
     480             :         } else {
     481        1145 :                 return 0;
     482             :         }
     483       55580 :         return 1;
     484             : }
     485             : /* }}} */
     486             : 
     487      256740 : ZEND_API int ZEND_FASTCALL zend_parse_arg_str_slow(zval *arg, zend_string **dest) /* {{{ */
     488             : {
     489      256740 :         if (UNEXPECTED(ZEND_ARG_USES_STRICT_TYPES())) {
     490           1 :                 return 0;
     491             :         }
     492      256739 :         return zend_parse_arg_str_weak(arg, dest);
     493             : }
     494             : /* }}} */
     495             : 
     496    24728759 : static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, const char **spec, char **error, int *severity) /* {{{ */
     497             : {
     498    24728759 :         const char *spec_walk = *spec;
     499    24728759 :         char c = *spec_walk++;
     500    24728759 :         int check_null = 0;
     501    24728759 :         int separate = 0;
     502    24728759 :         zval *real_arg = arg;
     503             : 
     504             :         /* scan through modifiers */
     505    24728759 :         ZVAL_DEREF(arg);
     506             :         while (1) {
     507    30700784 :                 if (*spec_walk == '/') {
     508     6021598 :                         SEPARATE_ZVAL_NOREF(arg);
     509     5874321 :                         real_arg = arg;
     510     5874321 :                         separate = 1;
     511    24826463 :                 } else if (*spec_walk == '!') {
     512       97704 :                         check_null = 1;
     513             :                 } else {
     514    24728759 :                         break;
     515             :                 }
     516     5972025 :                 spec_walk++;
     517     5972025 :         }
     518             : 
     519    24728759 :         switch (c) {
     520             :                 case 'l':
     521             :                 case 'L':
     522             :                         {
     523     7533817 :                                 zend_long *p = va_arg(*va, zend_long *);
     524     7533817 :                                 zend_bool *is_null = NULL;
     525             : 
     526     7533817 :                                 if (check_null) {
     527         376 :                                         is_null = va_arg(*va, zend_bool *);
     528             :                                 }
     529             : 
     530    15067634 :                                 if (!zend_parse_arg_long(arg, p, is_null, check_null, c == 'L')) {
     531       32001 :                                         return "integer";
     532             :                                 }
     533             :                         }
     534     7501816 :                         break;
     535             : 
     536             :                 case 'd':
     537             :                         {
     538        3797 :                                 double *p = va_arg(*va, double *);
     539        3797 :                                 zend_bool *is_null = NULL;
     540             : 
     541        3797 :                                 if (check_null) {
     542           0 :                                         is_null = va_arg(*va, zend_bool *);
     543             :                                 }
     544             : 
     545        3797 :                                 if (!zend_parse_arg_double(arg, p, is_null, check_null)) {
     546         317 :                                         return "float";
     547             :                                 }
     548             :                         }
     549        3480 :                         break;
     550             : 
     551             :                 case 's':
     552             :                         {
     553     2170495 :                                 char **p = va_arg(*va, char **);
     554     2170495 :                                 size_t *pl = va_arg(*va, size_t *);
     555     2170495 :                                 if (!zend_parse_arg_string(arg, p, pl, check_null)) {
     556         628 :                                         return "string";
     557             :                                 }
     558             :                         }
     559     2169867 :                         break;
     560             : 
     561             :                 case 'p':
     562             :                         {
     563      328239 :                                 char **p = va_arg(*va, char **);
     564      328239 :                                 size_t *pl = va_arg(*va, size_t *);
     565      328239 :                                 if (!zend_parse_arg_path(arg, p, pl, check_null)) {
     566         159 :                                         return "a valid path";
     567             :                                 }
     568             :                         }
     569      328080 :                         break;
     570             : 
     571             :                 case 'P':
     572             :                         {
     573         370 :                                 zend_string **str = va_arg(*va, zend_string **);
     574         370 :                                 if (!zend_parse_arg_path_str(arg, str, check_null)) {
     575           4 :                                         return "a valid path";
     576             :                                 }
     577             :                         }
     578         366 :                         break;
     579             : 
     580             :                 case 'S':
     581             :                         {
     582     1423023 :                                 zend_string **str = va_arg(*va, zend_string **);
     583     1423023 :                                 if (!zend_parse_arg_str(arg, str, check_null)) {
     584         343 :                                         return "string";
     585             :                                 }
     586             :                         }
     587     1422680 :                         break;
     588             : 
     589             :                 case 'b':
     590             :                         {
     591     2008801 :                                 zend_bool *p = va_arg(*va, zend_bool *);
     592     2008801 :                                 zend_bool *is_null = NULL;
     593             : 
     594     2008801 :                                 if (check_null) {
     595           0 :                                         is_null = va_arg(*va, zend_bool *);
     596             :                                 }
     597             : 
     598     2008801 :                                 if (!zend_parse_arg_bool(arg, p, is_null, check_null)) {
     599         130 :                                         return "boolean";
     600             :                                 }
     601             :                         }
     602     2008671 :                         break;
     603             : 
     604             :                 case 'r':
     605             :                         {
     606     3661516 :                                 zval **p = va_arg(*va, zval **);
     607             : 
     608     3661516 :                                 if (!zend_parse_arg_resource(arg, p, check_null)) {
     609        1689 :                                         return "resource";
     610             :                                 }
     611             :                         }
     612     3659827 :                         break;
     613             : 
     614             :                 case 'A':
     615             :                 case 'a':
     616             :                         {
     617      173092 :                                 zval **p = va_arg(*va, zval **);
     618             : 
     619      346184 :                                 if (!zend_parse_arg_array(arg, p, check_null, c == 'A')) {
     620        1028 :                                         return "array";
     621             :                                 }
     622             :                         }
     623      172064 :                         break;
     624             : 
     625             :                 case 'H':
     626             :                 case 'h':
     627             :                         {
     628         292 :                                 HashTable **p = va_arg(*va, HashTable **);
     629             : 
     630         584 :                                 if (!zend_parse_arg_array_ht(arg, p, check_null, c == 'H', separate)) {
     631          52 :                                         return "array";
     632             :                                 }
     633             :                         }
     634         240 :                         break;
     635             : 
     636             :                 case 'o':
     637             :                         {
     638       33497 :                                 zval **p = va_arg(*va, zval **);
     639             : 
     640       33497 :                                 if (!zend_parse_arg_object(arg, p, NULL, check_null)) {
     641         102 :                                         return "object";
     642             :                                 }
     643             :                         }
     644       33395 :                         break;
     645             : 
     646             :                 case 'O':
     647             :                         {
     648      676654 :                                 zval **p = va_arg(*va, zval **);
     649      676654 :                                 zend_class_entry *ce = va_arg(*va, zend_class_entry *);
     650             : 
     651      676654 :                                 if (!zend_parse_arg_object(arg, p, ce, check_null)) {
     652         944 :                                         if (ce) {
     653         944 :                                                 return ZSTR_VAL(ce->name);
     654             :                                         } else {
     655           0 :                                                 return "object";
     656             :                                         }
     657             :                                 }
     658             :                         }
     659      675710 :                         break;
     660             : 
     661             :                 case 'C':
     662             :                         {
     663          46 :                                 zend_class_entry *lookup, **pce = va_arg(*va, zend_class_entry **);
     664          46 :                                 zend_class_entry *ce_base = *pce;
     665             : 
     666          60 :                                 if (check_null && Z_TYPE_P(arg) == IS_NULL) {
     667           4 :                                         *pce = NULL;
     668           4 :                                         break;
     669             :                                 }
     670          42 :                                 convert_to_string_ex(arg);
     671          42 :                                 if ((lookup = zend_lookup_class(Z_STR_P(arg))) == NULL) {
     672           2 :                                         *pce = NULL;
     673             :                                 } else {
     674          40 :                                         *pce = lookup;
     675             :                                 }
     676          42 :                                 if (ce_base) {
     677          39 :                                         if ((!*pce || !instanceof_function(*pce, ce_base))) {
     678          18 :                                                 zend_spprintf(error, 0, "to be a class name derived from %s, '%s' given",
     679          18 :                                                         ZSTR_VAL(ce_base->name), Z_STRVAL_P(arg));
     680           9 :                                                 *pce = NULL;
     681           9 :                                                 return "";
     682             :                                         }
     683             :                                 }
     684          33 :                                 if (!*pce) {
     685           0 :                                         zend_spprintf(error, 0, "to be a valid class name, '%s' given",
     686           0 :                                                 Z_STRVAL_P(arg));
     687           0 :                                         return "";
     688             :                                 }
     689          33 :                                 break;
     690             : 
     691             :                         }
     692             :                         break;
     693             : 
     694             :                 case 'f':
     695             :                         {
     696        2254 :                                 zend_fcall_info *fci = va_arg(*va, zend_fcall_info *);
     697        2254 :                                 zend_fcall_info_cache *fcc = va_arg(*va, zend_fcall_info_cache *);
     698        2254 :                                 char *is_callable_error = NULL;
     699             : 
     700        2260 :                                 if (check_null && Z_TYPE_P(arg) == IS_NULL) {
     701           1 :                                         fci->size = 0;
     702           1 :                                         fcc->initialized = 0;
     703           1 :                                         break;
     704             :                                 }
     705             : 
     706        2253 :                                 if (zend_fcall_info_init(arg, 0, fci, fcc, NULL, &is_callable_error) == SUCCESS) {
     707        1657 :                                         if (is_callable_error) {
     708           0 :                                                 *severity = E_DEPRECATED;
     709           0 :                                                 zend_spprintf(error, 0, "to be a valid callback, %s", is_callable_error);
     710           0 :                                                 efree(is_callable_error);
     711           0 :                                                 *spec = spec_walk;
     712           0 :                                                 return "";
     713             :                                         }
     714        1657 :                                         break;
     715             :                                 } else {
     716         596 :                                         if (is_callable_error) {
     717         596 :                                                 *severity = E_ERROR;
     718         596 :                                                 zend_spprintf(error, 0, "to be a valid callback, %s", is_callable_error);
     719         596 :                                                 efree(is_callable_error);
     720         596 :                                                 return "";
     721             :                                         } else {
     722           0 :                                                 return "valid callback";
     723             :                                         }
     724             :                                 }
     725             :                         }
     726             : 
     727             :                 case 'z':
     728             :                         {
     729     6712866 :                                 zval **p = va_arg(*va, zval **);
     730             : 
     731             :                                 zend_parse_arg_zval_deref(real_arg, p, check_null);
     732             :                         }
     733     6712866 :                         break;
     734             : 
     735             :                 case 'Z':
     736             :                         /* 'Z' iz not supported anymore and should be replaced with 'z' */
     737             :                         ZEND_ASSERT(c != 'Z');
     738             :                 default:
     739           0 :                         return "unknown";
     740             :         }
     741             : 
     742    24690757 :         *spec = spec_walk;
     743             : 
     744    24690757 :         return NULL;
     745             : }
     746             : /* }}} */
     747             : 
     748    24728759 : static int zend_parse_arg(int arg_num, zval *arg, va_list *va, const char **spec, int flags) /* {{{ */
     749             : {
     750    24728759 :         const char *expected_type = NULL;
     751    24728759 :         char *error = NULL;
     752    24728759 :         int severity = 0;
     753             : 
     754    24728759 :         expected_type = zend_parse_arg_impl(arg_num, arg, va, spec, &error, &severity);
     755    24728759 :         if (expected_type) {
     756       38002 :                 if (!(flags & ZEND_PARSE_PARAMS_QUIET) && (*expected_type || error)) {
     757             :                         const char *space;
     758        7042 :                         const char *class_name = get_active_class_name(&space);
     759             :                         zend_bool throw_exception =
     760        7042 :                                 ZEND_ARG_USES_STRICT_TYPES() || (flags & ZEND_PARSE_PARAMS_THROW);
     761             : 
     762        7042 :                         if (error) {
     763         605 :                                 zend_internal_type_error(throw_exception, "%s%s%s() expects parameter %d %s",
     764             :                                                 class_name, space, get_active_function_name(), arg_num, error);
     765         605 :                                 efree(error);
     766             :                         } else {
     767        6437 :                                 zend_internal_type_error(throw_exception,
     768             :                                                 "%s%s%s() expects parameter %d to be %s, %s given",
     769             :                                                 class_name, space, get_active_function_name(), arg_num, expected_type,
     770             :                                                 zend_zval_type_name(arg));
     771             :                         }
     772             :                 }
     773       38002 :                 if (severity != E_DEPRECATED) {
     774       38002 :                         return FAILURE;
     775             :                 }
     776             :         }
     777             : 
     778    24690757 :         return SUCCESS;
     779             : }
     780             : /* }}} */
     781             : 
     782           0 : ZEND_API int zend_parse_parameter(int flags, int arg_num, zval *arg, const char *spec, ...)
     783             : {
     784             :         va_list va;
     785             :         int ret;
     786             : 
     787           0 :         va_start(va, spec);
     788           0 :         ret = zend_parse_arg(arg_num, arg, &va, &spec, flags);
     789           0 :         va_end(va);
     790             : 
     791           0 :         return ret;
     792             : }
     793             : 
     794           0 : static ZEND_COLD void zend_parse_parameters_debug_error(const char *msg) {
     795           0 :         zend_function *active_function = EG(current_execute_data)->func;
     796           0 :         const char *class_name = active_function->common.scope
     797           0 :                 ? ZSTR_VAL(active_function->common.scope->name) : "";
     798           0 :         zend_error_noreturn(E_CORE_ERROR, "%s%s%s(): %s",
     799           0 :                 class_name, class_name[0] ? "::" : "",
     800           0 :                 ZSTR_VAL(active_function->common.function_name), msg);
     801             : }
     802             : 
     803    13684063 : static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va, int flags) /* {{{ */
     804             : {
     805             :         const  char *spec_walk;
     806             :         int c, i;
     807    13684063 :         int min_num_args = -1;
     808    13684063 :         int max_num_args = 0;
     809    13684063 :         int post_varargs = 0;
     810             :         zval *arg;
     811             :         int arg_count;
     812    13684063 :         zend_bool have_varargs = 0;
     813    13684063 :         zval **varargs = NULL;
     814    13684063 :         int *n_varargs = NULL;
     815             : 
     816    53127138 :         for (spec_walk = type_spec; *spec_walk; spec_walk++) {
     817    39443075 :                 c = *spec_walk;
     818    39443075 :                 switch (c) {
     819             :                         case 'l': case 'd':
     820             :                         case 's': case 'b':
     821             :                         case 'r': case 'a':
     822             :                         case 'o': case 'O':
     823             :                         case 'z': case 'Z':
     824             :                         case 'C': case 'h':
     825             :                         case 'f': case 'A':
     826             :                         case 'H': case 'p':
     827             :                         case 'S': case 'P':
     828             :                         case 'L':
     829    27896581 :                                 max_num_args++;
     830    27896581 :                                 break;
     831             : 
     832             :                         case '|':
     833     5111270 :                                 min_num_args = max_num_args;
     834     5111270 :                                 break;
     835             : 
     836             :                         case '/':
     837             :                         case '!':
     838             :                                 /* Pass */
     839     6113557 :                                 break;
     840             : 
     841             :                         case '*':
     842             :                         case '+':
     843      321667 :                                 if (have_varargs) {
     844           0 :                                         zend_parse_parameters_debug_error(
     845             :                                                 "only one varargs specifier (* or +) is permitted");
     846           0 :                                         return FAILURE;
     847             :                                 }
     848      321667 :                                 have_varargs = 1;
     849             :                                 /* we expect at least one parameter in varargs */
     850      321667 :                                 if (c == '+') {
     851      160670 :                                         max_num_args++;
     852             :                                 }
     853             :                                 /* mark the beginning of varargs */
     854      321667 :                                 post_varargs = max_num_args;
     855      321667 :                                 break;
     856             : 
     857             :                         default:
     858           0 :                                 zend_parse_parameters_debug_error("bad type specifier while parsing parameters");
     859           0 :                                 return FAILURE;
     860             :                 }
     861             :         }
     862             : 
     863    13684063 :         if (min_num_args < 0) {
     864     8572793 :                 min_num_args = max_num_args;
     865             :         }
     866             : 
     867    13684063 :         if (have_varargs) {
     868             :                 /* calculate how many required args are at the end of the specifier list */
     869      321667 :                 post_varargs = max_num_args - post_varargs;
     870      321667 :                 max_num_args = -1;
     871             :         }
     872             : 
     873    13684063 :         if (num_args < min_num_args || (num_args > max_num_args && max_num_args >= 0)) {
     874        2472 :                 if (!(flags & ZEND_PARSE_PARAMS_QUIET)) {
     875        2329 :                         zend_function *active_function = EG(current_execute_data)->func;
     876        2329 :                         const char *class_name = active_function->common.scope ? ZSTR_VAL(active_function->common.scope->name) : "";
     877        2329 :                         zend_bool throw_exception = ZEND_ARG_USES_STRICT_TYPES() || (flags & ZEND_PARSE_PARAMS_THROW);
     878        6987 :                         zend_internal_type_error(throw_exception, "%s%s%s() expects %s %d parameter%s, %d given",
     879             :                                         class_name,
     880        2329 :                                         class_name[0] ? "::" : "",
     881        2329 :                                         ZSTR_VAL(active_function->common.function_name),
     882             :                                         min_num_args == max_num_args ? "exactly" : num_args < min_num_args ? "at least" : "at most",
     883             :                                         num_args < min_num_args ? min_num_args : max_num_args,
     884             :                                         (num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
     885             :                                         num_args);
     886             :                 }
     887        2472 :                 return FAILURE;
     888             :         }
     889             : 
     890    13681591 :         arg_count = ZEND_CALL_NUM_ARGS(EG(current_execute_data));
     891             : 
     892    13681591 :         if (num_args > arg_count) {
     893           0 :                 zend_parse_parameters_debug_error("could not obtain parameters for parsing");
     894           0 :                 return FAILURE;
     895             :         }
     896             : 
     897    13681591 :         i = 0;
     898    52368077 :         while (num_args-- > 0) {
     899    25042897 :                 if (*type_spec == '|') {
     900     2537994 :                         type_spec++;
     901             :                 }
     902             : 
     903    25042897 :                 if (*type_spec == '*' || *type_spec == '+') {
     904      314138 :                         int num_varargs = num_args + 1 - post_varargs;
     905             : 
     906             :                         /* eat up the passed in storage even if it won't be filled in with varargs */
     907      314138 :                         varargs = va_arg(*va, zval **);
     908      314138 :                         n_varargs = va_arg(*va, int *);
     909      314138 :                         type_spec++;
     910             : 
     911      314138 :                         if (num_varargs > 0) {
     912      314138 :                                 *n_varargs = num_varargs;
     913      314138 :                                 *varargs = ZEND_CALL_ARG(EG(current_execute_data), i + 1);
     914             :                                 /* adjust how many args we have left and restart loop */
     915      314138 :                                 num_args += 1 - num_varargs;
     916      314138 :                                 i += num_varargs;
     917      314138 :                                 continue;
     918             :                         } else {
     919           0 :                                 *varargs = NULL;
     920           0 :                                 *n_varargs = 0;
     921             :                         }
     922             :                 }
     923             : 
     924    24728759 :                 arg = ZEND_CALL_ARG(EG(current_execute_data), i + 1);
     925             : 
     926    24728759 :                 if (zend_parse_arg(i+1, arg, va, &type_spec, flags) == FAILURE) {
     927             :                         /* clean up varargs array if it was used */
     928       38002 :                         if (varargs && *varargs) {
     929         418 :                                 *varargs = NULL;
     930             :                         }
     931       38002 :                         return FAILURE;
     932             :                 }
     933    24690757 :                 i++;
     934             :         }
     935             : 
     936    13643589 :         return SUCCESS;
     937             : }
     938             : /* }}} */
     939             : 
     940       34646 : ZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_spec, ...) /* {{{ */
     941             : {
     942             :         va_list va;
     943             :         int retval;
     944             : 
     945       34646 :         va_start(va, type_spec);
     946       34646 :         retval = zend_parse_va_args(num_args, type_spec, &va, flags);
     947       34646 :         va_end(va);
     948             : 
     949       34646 :         return retval;
     950             : }
     951             : /* }}} */
     952             : 
     953    12574702 : ZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...) /* {{{ */
     954             : {
     955             :         va_list va;
     956             :         int retval;
     957    12574702 :         int flags = 0;
     958             : 
     959    12574702 :         va_start(va, type_spec);
     960    12574702 :         retval = zend_parse_va_args(num_args, type_spec, &va, flags);
     961    12574702 :         va_end(va);
     962             : 
     963    12574702 :         return retval;
     964             : }
     965             : /* }}} */
     966             : 
     967      387812 : ZEND_API int zend_parse_parameters_throw(int num_args, const char *type_spec, ...) /* {{{ */
     968             : {
     969             :         va_list va;
     970             :         int retval;
     971      387812 :         int flags = ZEND_PARSE_PARAMS_THROW;
     972             : 
     973      387812 :         va_start(va, type_spec);
     974      387812 :         retval = zend_parse_va_args(num_args, type_spec, &va, flags);
     975      387812 :         va_end(va);
     976             : 
     977      387812 :         return retval;
     978             : }
     979             : /* }}} */
     980             : 
     981      686903 : ZEND_API int zend_parse_method_parameters(int num_args, zval *this_ptr, const char *type_spec, ...) /* {{{ */
     982             : {
     983             :         va_list va;
     984             :         int retval;
     985      686903 :         int flags = 0;
     986      686903 :         const char *p = type_spec;
     987             :         zval **object;
     988             :         zend_class_entry *ce;
     989             : 
     990             :         /* Just checking this_ptr is not enough, because fcall_common_helper does not set
     991             :          * Z_OBJ(EG(This)) to NULL when calling an internal function with common.scope == NULL.
     992             :          * In that case EG(This) would still be the $this from the calling code and we'd take the
     993             :          * wrong branch here. */
     994      686903 :         zend_bool is_method = EG(current_execute_data)->func->common.scope != NULL;
     995             : 
     996     1373806 :         if (!is_method || !this_ptr || Z_TYPE_P(this_ptr) != IS_OBJECT) {
     997      326725 :                 va_start(va, type_spec);
     998      326725 :                 retval = zend_parse_va_args(num_args, type_spec, &va, flags);
     999      326725 :                 va_end(va);
    1000             :         } else {
    1001      360178 :                 p++;
    1002             : 
    1003      360178 :                 va_start(va, type_spec);
    1004             : 
    1005      360178 :                 object = va_arg(va, zval **);
    1006      360178 :                 ce = va_arg(va, zend_class_entry *);
    1007      360178 :                 *object = this_ptr;
    1008             : 
    1009      360178 :                 if (ce && !instanceof_function(Z_OBJCE_P(this_ptr), ce)) {
    1010           0 :                         zend_error_noreturn(E_CORE_ERROR, "%s::%s() must be derived from %s::%s",
    1011           0 :                                 ZSTR_VAL(Z_OBJCE_P(this_ptr)->name), get_active_function_name(), ZSTR_VAL(ce->name), get_active_function_name());
    1012             :                 }
    1013             : 
    1014      360178 :                 retval = zend_parse_va_args(num_args, p, &va, flags);
    1015      360178 :                 va_end(va);
    1016             :         }
    1017      686903 :         return retval;
    1018             : }
    1019             : /* }}} */
    1020             : 
    1021           0 : ZEND_API int zend_parse_method_parameters_ex(int flags, int num_args, zval *this_ptr, const char *type_spec, ...) /* {{{ */
    1022             : {
    1023             :         va_list va;
    1024             :         int retval;
    1025           0 :         const char *p = type_spec;
    1026             :         zval **object;
    1027             :         zend_class_entry *ce;
    1028             : 
    1029           0 :         if (!this_ptr) {
    1030           0 :                 va_start(va, type_spec);
    1031           0 :                 retval = zend_parse_va_args(num_args, type_spec, &va, flags);
    1032           0 :                 va_end(va);
    1033             :         } else {
    1034           0 :                 p++;
    1035           0 :                 va_start(va, type_spec);
    1036             : 
    1037           0 :                 object = va_arg(va, zval **);
    1038           0 :                 ce = va_arg(va, zend_class_entry *);
    1039           0 :                 *object = this_ptr;
    1040             : 
    1041           0 :                 if (ce && !instanceof_function(Z_OBJCE_P(this_ptr), ce)) {
    1042           0 :                         if (!(flags & ZEND_PARSE_PARAMS_QUIET)) {
    1043           0 :                                 zend_error_noreturn(E_CORE_ERROR, "%s::%s() must be derived from %s::%s",
    1044           0 :                                         ZSTR_VAL(ce->name), get_active_function_name(), ZSTR_VAL(Z_OBJCE_P(this_ptr)->name), get_active_function_name());
    1045             :                         }
    1046           0 :                         va_end(va);
    1047           0 :                         return FAILURE;
    1048             :                 }
    1049             : 
    1050           0 :                 retval = zend_parse_va_args(num_args, p, &va, flags);
    1051           0 :                 va_end(va);
    1052             :         }
    1053           0 :         return retval;
    1054             : }
    1055             : /* }}} */
    1056             : 
    1057             : /* Argument parsing API -- andrei */
    1058     2796753 : ZEND_API int _array_init(zval *arg, uint32_t size ZEND_FILE_LINE_DC) /* {{{ */
    1059             : {
    1060     2796753 :         ZVAL_NEW_ARR(arg);
    1061     2796753 :         _zend_hash_init(Z_ARRVAL_P(arg), size, ZVAL_PTR_DTOR, 0 ZEND_FILE_LINE_RELAY_CC);
    1062     2796753 :         return SUCCESS;
    1063             : }
    1064             : /* }}} */
    1065             : 
    1066             : /* This function should be called after the constructor has been called
    1067             :  * because it may call __set from the uninitialized object otherwise. */
    1068           9 : ZEND_API void zend_merge_properties(zval *obj, HashTable *properties) /* {{{ */
    1069             : {
    1070           9 :         const zend_object_handlers *obj_ht = Z_OBJ_HT_P(obj);
    1071           9 :         zend_class_entry *old_scope = EG(fake_scope);
    1072             :         zend_string *key;
    1073             :         zval *value;
    1074             : 
    1075           9 :         EG(fake_scope) = Z_OBJCE_P(obj);
    1076          45 :         ZEND_HASH_FOREACH_STR_KEY_VAL(properties, key, value) {
    1077          18 :                 if (key) {
    1078             :                         zval member;
    1079             : 
    1080          18 :                         ZVAL_STR(&member, key);
    1081          18 :                         obj_ht->write_property(obj, &member, value, NULL);
    1082             :                 }
    1083             :         } ZEND_HASH_FOREACH_END();
    1084           9 :         EG(fake_scope) = old_scope;
    1085           9 : }
    1086             : /* }}} */
    1087             : 
    1088        8020 : ZEND_API int zend_update_class_constants(zend_class_entry *class_type) /* {{{ */
    1089             : {
    1090        8020 :         if (!(class_type->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
    1091          26 :                 class_type->ce_flags |= ZEND_ACC_CONSTANTS_UPDATED;
    1092             : 
    1093          26 :                 if (class_type->parent) {
    1094           5 :                         if (UNEXPECTED(zend_update_class_constants(class_type->parent) != SUCCESS)) {
    1095           0 :                                 return FAILURE;
    1096             :                         }
    1097             :                 }
    1098             : 
    1099          26 :                 if (!CE_STATIC_MEMBERS(class_type) && class_type->default_static_members_count) {
    1100             :                         /* initialize static members of internal class */
    1101             :                         int i;
    1102             :                         zval *p;
    1103             : 
    1104             : #if ZTS
    1105             :                         CG(static_members_table)[(zend_intptr_t)(class_type->static_members_table)] = emalloc(sizeof(zval) * class_type->default_static_members_count);
    1106             : #else
    1107           0 :                         class_type->static_members_table = emalloc(sizeof(zval) * class_type->default_static_members_count);
    1108             : #endif
    1109           0 :                         for (i = 0; i < class_type->default_static_members_count; i++) {
    1110           0 :                                 p = &class_type->default_static_members_table[i];
    1111           0 :                                 if (Z_ISREF_P(p) &&
    1112           0 :                                         class_type->parent &&
    1113           0 :                                         i < class_type->parent->default_static_members_count &&
    1114           0 :                                         p == &class_type->parent->default_static_members_table[i] &&
    1115           0 :                                         Z_TYPE(CE_STATIC_MEMBERS(class_type->parent)[i]) != IS_UNDEF
    1116             :                                 ) {
    1117           0 :                                         zval *q = &CE_STATIC_MEMBERS(class_type->parent)[i];
    1118             : 
    1119           0 :                                         ZVAL_NEW_REF(q, q);
    1120           0 :                                         ZVAL_COPY_VALUE(&CE_STATIC_MEMBERS(class_type)[i], q);
    1121             :                                         Z_ADDREF_P(q);
    1122             :                                 } else {
    1123           0 :                                         ZVAL_DUP(&CE_STATIC_MEMBERS(class_type)[i], p);
    1124             :                                 }
    1125             :                         }
    1126             :                 } else {
    1127             :                         zend_class_entry *ce;
    1128             :                         zend_class_constant *c;
    1129             :                         zval *val;
    1130             :                         zend_property_info *prop_info;
    1131             : 
    1132          59 :                         ZEND_HASH_FOREACH_PTR(&class_type->constants_table, c) {
    1133          17 :                                 val = &c->value;
    1134          17 :                                 if (Z_CONSTANT_P(val)) {
    1135           3 :                                         if (UNEXPECTED(zval_update_constant_ex(val, class_type) != SUCCESS)) {
    1136           0 :                                                 return FAILURE;
    1137             :                                         }
    1138             :                                 }
    1139             :                         } ZEND_HASH_FOREACH_END();
    1140             : 
    1141          25 :                         ce = class_type;
    1142          81 :                         while (ce) {
    1143         189 :                                 ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) {
    1144          79 :                                         if (prop_info->ce == ce) {
    1145          73 :                                                 if (prop_info->flags & ZEND_ACC_STATIC) {
    1146          50 :                                                         val = CE_STATIC_MEMBERS(class_type) + prop_info->offset;
    1147             :                                                 } else {
    1148          23 :                                                         val = (zval*)((char*)class_type->default_properties_table + prop_info->offset - OBJ_PROP_TO_OFFSET(0));
    1149             :                                                 }
    1150          73 :                                                 ZVAL_DEREF(val);
    1151          73 :                                                 if (Z_CONSTANT_P(val)) {
    1152          57 :                                                         if (UNEXPECTED(zval_update_constant_ex(val, ce) != SUCCESS)) {
    1153           0 :                                                                 return FAILURE;
    1154             :                                                         }
    1155             :                                                 }
    1156             :                                         }
    1157             :                                 } ZEND_HASH_FOREACH_END();
    1158          31 :                                 ce = ce->parent;
    1159             :                         }
    1160             :                 }
    1161             :         }
    1162        8019 :         return SUCCESS;
    1163             : }
    1164             : /* }}} */
    1165             : 
    1166     1959356 : ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type) /* {{{ */
    1167             : {
    1168     1959356 :         if (class_type->default_properties_count) {
    1169      224588 :                 zval *src = class_type->default_properties_table;
    1170      224588 :                 zval *dst = object->properties_table;
    1171      224588 :                 zval *end = src + class_type->default_properties_count;
    1172             : 
    1173             :                 do {
    1174             : #if ZTS
    1175             :                         ZVAL_DUP(dst, src);
    1176             : #else
    1177      381267 :                         ZVAL_COPY(dst, src);
    1178             : #endif
    1179      381267 :                         src++;
    1180      381267 :                         dst++;
    1181      381267 :                 } while (src != end);
    1182      224588 :                 object->properties = NULL;
    1183             :         }
    1184     1959356 : }
    1185             : /* }}} */
    1186             : 
    1187         112 : ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properties) /* {{{ */
    1188             : {
    1189         112 :         object->properties = properties;
    1190         112 :         if (object->ce->default_properties_count) {
    1191             :                 zval *prop;
    1192             :                 zend_string *key;
    1193             :                 zend_property_info *property_info;
    1194             : 
    1195           0 :                 ZEND_HASH_FOREACH_STR_KEY_VAL(properties, key, prop) {
    1196           0 :                         property_info = zend_get_property_info(object->ce, key, 1);
    1197           0 :                         if (property_info != ZEND_WRONG_PROPERTY_INFO &&
    1198             :                             property_info &&
    1199           0 :                             (property_info->flags & ZEND_ACC_STATIC) == 0) {
    1200           0 :                                 zval *slot = OBJ_PROP(object, property_info->offset);
    1201           0 :                                 ZVAL_COPY_VALUE(slot, prop);
    1202           0 :                                 ZVAL_INDIRECT(prop, slot);
    1203             :                         }
    1204             :                 } ZEND_HASH_FOREACH_END();
    1205             :         }
    1206         112 : }
    1207             : /* }}} */
    1208             : 
    1209          35 : ZEND_API void object_properties_load(zend_object *object, HashTable *properties) /* {{{ */
    1210             : {
    1211             :     zval *prop, tmp;
    1212             :         zend_string *key;
    1213             :         zend_long h;
    1214             :         zend_property_info *property_info;
    1215             : 
    1216          75 :         ZEND_HASH_FOREACH_KEY_VAL(properties, h, key, prop) {
    1217          20 :                 if (key) {
    1218          19 :                         if (ZSTR_VAL(key)[0] == '\0') {
    1219             :                                 const char *class_name, *prop_name;
    1220             :                                 size_t prop_name_len;
    1221           9 :                                 if (zend_unmangle_property_name_ex(key, &class_name, &prop_name, &prop_name_len) == SUCCESS) {
    1222          18 :                                         zend_string *pname = zend_string_init(prop_name, prop_name_len, 0);
    1223           9 :                                         zend_class_entry *prev_scope = EG(fake_scope);
    1224           9 :                                         if (class_name && class_name[0] != '*') {
    1225           8 :                                                 zend_string *cname = zend_string_init(class_name, strlen(class_name), 0);
    1226           4 :                                                 EG(fake_scope) = zend_lookup_class(cname);
    1227             :                                                 zend_string_release(cname);
    1228             :                                         }
    1229           9 :                                         property_info = zend_get_property_info(object->ce, pname, 1);
    1230             :                                         zend_string_release(pname);
    1231           9 :                                         EG(fake_scope) = prev_scope;
    1232             :                                 } else {
    1233           0 :                                         property_info = ZEND_WRONG_PROPERTY_INFO;
    1234             :                                 }
    1235             :                         } else {
    1236          10 :                                 property_info = zend_get_property_info(object->ce, key, 1);
    1237             :                         }
    1238          57 :                         if (property_info != ZEND_WRONG_PROPERTY_INFO &&
    1239             :                                 property_info &&
    1240          19 :                                 (property_info->flags & ZEND_ACC_STATIC) == 0) {
    1241          19 :                                 zval *slot = OBJ_PROP(object, property_info->offset);
    1242          19 :                                 zval_ptr_dtor(slot);
    1243          19 :                                 ZVAL_COPY_VALUE(slot, prop);
    1244          19 :                                 zval_add_ref(slot);
    1245          19 :                                 if (object->properties) {
    1246           0 :                                         ZVAL_INDIRECT(&tmp, slot);
    1247           0 :                                         zend_hash_update(object->properties, key, &tmp);
    1248             :                                 }
    1249             :                         } else {
    1250           0 :                                 if (!object->properties) {
    1251           0 :                                         rebuild_object_properties(object);
    1252             :                                 }
    1253           0 :                                 prop = zend_hash_update(object->properties, key, prop);
    1254           0 :                                 zval_add_ref(prop);
    1255             :                         }
    1256             :                 } else {
    1257           1 :                         if (!object->properties) {
    1258           1 :                                 rebuild_object_properties(object);
    1259             :                         }
    1260           1 :                         prop = zend_hash_index_update(object->properties, h, prop);
    1261           1 :                         zval_add_ref(prop);
    1262             :                 }
    1263             :         } ZEND_HASH_FOREACH_END();
    1264          35 : }
    1265             : /* }}} */
    1266             : 
    1267             : /* This function requires 'properties' to contain all props declared in the
    1268             :  * class and all props being public. If only a subset is given or the class
    1269             :  * has protected members then you need to merge the properties separately by
    1270             :  * calling zend_merge_properties(). */
    1271     1568118 : ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *class_type, HashTable *properties ZEND_FILE_LINE_DC) /* {{{ */
    1272             : {
    1273     1568118 :         if (UNEXPECTED(class_type->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT|ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) {
    1274           9 :                 if (class_type->ce_flags & ZEND_ACC_INTERFACE) {
    1275           2 :                         zend_throw_error(NULL, "Cannot instantiate interface %s", ZSTR_VAL(class_type->name));
    1276           7 :                 } else if (class_type->ce_flags & ZEND_ACC_TRAIT) {
    1277           2 :                         zend_throw_error(NULL, "Cannot instantiate trait %s", ZSTR_VAL(class_type->name));
    1278             :                 } else {
    1279           5 :                         zend_throw_error(NULL, "Cannot instantiate abstract class %s", ZSTR_VAL(class_type->name));
    1280             :                 }
    1281           9 :                 ZVAL_NULL(arg);
    1282           9 :                 Z_OBJ_P(arg) = NULL;
    1283           9 :                 return FAILURE;
    1284             :         }
    1285             : 
    1286     1568109 :         if (UNEXPECTED(!(class_type->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
    1287          10 :                 if (UNEXPECTED(zend_update_class_constants(class_type) != SUCCESS)) {
    1288           0 :                         ZVAL_NULL(arg);
    1289           0 :                         Z_OBJ_P(arg) = NULL;
    1290           0 :                         return FAILURE;
    1291             :                 }
    1292             :         }
    1293             : 
    1294     1568108 :         if (class_type->create_object == NULL) {
    1295      931459 :                 ZVAL_OBJ(arg, zend_objects_new(class_type));
    1296      931459 :                 if (properties) {
    1297         112 :                         object_properties_init_ex(Z_OBJ_P(arg), properties);
    1298             :                 } else {
    1299      931347 :                         object_properties_init(Z_OBJ_P(arg), class_type);
    1300             :                 }
    1301             :         } else {
    1302      636649 :                 ZVAL_OBJ(arg, class_type->create_object(class_type));
    1303             :         }
    1304     1568108 :         return SUCCESS;
    1305             : }
    1306             : /* }}} */
    1307             : 
    1308     1567923 : ZEND_API int _object_init_ex(zval *arg, zend_class_entry *class_type ZEND_FILE_LINE_DC) /* {{{ */
    1309             : {
    1310     1567923 :         return _object_and_properties_init(arg, class_type, 0 ZEND_FILE_LINE_RELAY_CC);
    1311             : }
    1312             : /* }}} */
    1313             : 
    1314        1640 : ZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC) /* {{{ */
    1315             : {
    1316        1640 :         return _object_init_ex(arg, zend_standard_class_def ZEND_FILE_LINE_RELAY_CC);
    1317             : }
    1318             : /* }}} */
    1319             : 
    1320      134589 : ZEND_API int add_assoc_long_ex(zval *arg, const char *key, size_t key_len, zend_long n) /* {{{ */
    1321             : {
    1322             :         zval *ret, tmp;
    1323             : 
    1324      134589 :         ZVAL_LONG(&tmp, n);
    1325      269178 :         ret = zend_symtable_str_update(Z_ARRVAL_P(arg), key, key_len, &tmp);
    1326      134589 :         return ret ? SUCCESS : FAILURE;
    1327             : }
    1328             : /* }}} */
    1329             : 
    1330        1021 : ZEND_API int add_assoc_null_ex(zval *arg, const char *key, size_t key_len) /* {{{ */
    1331             : {
    1332             :         zval *ret, tmp;
    1333             : 
    1334        1021 :         ZVAL_NULL(&tmp);
    1335        2042 :         ret = zend_symtable_str_update(Z_ARRVAL_P(arg), key, key_len, &tmp);
    1336        1021 :         return ret ? SUCCESS : FAILURE;
    1337             : }
    1338             : /* }}} */
    1339             : 
    1340       92748 : ZEND_API int add_assoc_bool_ex(zval *arg, const char *key, size_t key_len, int b) /* {{{ */
    1341             : {
    1342             :         zval *ret, tmp;
    1343             : 
    1344       92748 :         ZVAL_BOOL(&tmp, b);
    1345      185496 :         ret = zend_symtable_str_update(Z_ARRVAL_P(arg), key, key_len, &tmp);
    1346       92748 :         return ret ? SUCCESS : FAILURE;
    1347             : }
    1348             : /* }}} */
    1349             : 
    1350           0 : ZEND_API int add_assoc_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r) /* {{{ */
    1351             : {
    1352             :         zval *ret, tmp;
    1353             : 
    1354           0 :         ZVAL_RES(&tmp, r);
    1355           0 :         ret = zend_symtable_str_update(Z_ARRVAL_P(arg), key, key_len, &tmp);
    1356           0 :         return ret ? SUCCESS : FAILURE;
    1357             : }
    1358             : /* }}} */
    1359             : 
    1360         892 : ZEND_API int add_assoc_double_ex(zval *arg, const char *key, size_t key_len, double d) /* {{{ */
    1361             : {
    1362             :         zval *ret, tmp;
    1363             : 
    1364         892 :         ZVAL_DOUBLE(&tmp, d);
    1365        1784 :         ret = zend_symtable_str_update(Z_ARRVAL_P(arg), key, key_len, &tmp);
    1366         892 :         return ret ? SUCCESS : FAILURE;
    1367             : }
    1368             : /* }}} */
    1369             : 
    1370        8882 : ZEND_API int add_assoc_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str) /* {{{ */
    1371             : {
    1372             :         zval *ret, tmp;
    1373             : 
    1374        8882 :         ZVAL_STR(&tmp, str);
    1375       17764 :         ret = zend_symtable_str_update(Z_ARRVAL_P(arg), key, key_len, &tmp);
    1376        8882 :         return ret ? SUCCESS : FAILURE;
    1377             : }
    1378             : /* }}} */
    1379             : 
    1380      102579 : ZEND_API int add_assoc_string_ex(zval *arg, const char *key, size_t key_len, char *str) /* {{{ */
    1381             : {
    1382             :         zval *ret, tmp;
    1383             : 
    1384      205158 :         ZVAL_STRING(&tmp, str);
    1385      205158 :         ret = zend_symtable_str_update(Z_ARRVAL_P(arg), key, key_len, &tmp);
    1386      102579 :         return ret ? SUCCESS : FAILURE;
    1387             : }
    1388             : /* }}} */
    1389             : 
    1390       10752 : ZEND_API int add_assoc_stringl_ex(zval *arg, const char *key, size_t key_len, char *str, size_t length) /* {{{ */
    1391             : {
    1392             :         zval *ret, tmp;
    1393             : 
    1394       21504 :         ZVAL_STRINGL(&tmp, str, length);
    1395       21504 :         ret = zend_symtable_str_update(Z_ARRVAL_P(arg), key, key_len, &tmp);
    1396       10752 :         return ret ? SUCCESS : FAILURE;
    1397             : }
    1398             : /* }}} */
    1399             : 
    1400      387028 : ZEND_API int add_assoc_zval_ex(zval *arg, const char *key, size_t key_len, zval *value) /* {{{ */
    1401             : {
    1402             :         zval *ret;
    1403             : 
    1404      774056 :         ret = zend_symtable_str_update(Z_ARRVAL_P(arg), key, key_len, value);
    1405      387028 :         return ret ? SUCCESS : FAILURE;
    1406             : }
    1407             : /* }}} */
    1408             : 
    1409       11629 : ZEND_API int add_index_long(zval *arg, zend_ulong index, zend_long n) /* {{{ */
    1410             : {
    1411             :         zval tmp;
    1412             : 
    1413       11629 :         ZVAL_LONG(&tmp, n);
    1414       11629 :         return zend_hash_index_update(Z_ARRVAL_P(arg), index, &tmp) ? SUCCESS : FAILURE;
    1415             : }
    1416             : /* }}} */
    1417             : 
    1418       16944 : ZEND_API int add_index_null(zval *arg, zend_ulong index) /* {{{ */
    1419             : {
    1420             :         zval tmp;
    1421             : 
    1422       16944 :         ZVAL_NULL(&tmp);
    1423       16944 :         return zend_hash_index_update(Z_ARRVAL_P(arg), index, &tmp) ? SUCCESS : FAILURE;
    1424             : }
    1425             : /* }}} */
    1426             : 
    1427         220 : ZEND_API int add_index_bool(zval *arg, zend_ulong index, int b) /* {{{ */
    1428             : {
    1429             :         zval tmp;
    1430             : 
    1431         220 :         ZVAL_BOOL(&tmp, b);
    1432         220 :         return zend_hash_index_update(Z_ARRVAL_P(arg), index, &tmp) ? SUCCESS : FAILURE;
    1433             : }
    1434             : /* }}} */
    1435             : 
    1436           0 : ZEND_API int add_index_resource(zval *arg, zend_ulong index, zend_resource *r) /* {{{ */
    1437             : {
    1438             :         zval tmp;
    1439             : 
    1440           0 :         ZVAL_RES(&tmp, r);
    1441           0 :         return zend_hash_index_update(Z_ARRVAL_P(arg), index, &tmp) ? SUCCESS : FAILURE;
    1442             : }
    1443             : /* }}} */
    1444             : 
    1445         770 : ZEND_API int add_index_double(zval *arg, zend_ulong index, double d) /* {{{ */
    1446             : {
    1447             :         zval tmp;
    1448             : 
    1449         770 :         ZVAL_DOUBLE(&tmp, d);
    1450         770 :         return zend_hash_index_update(Z_ARRVAL_P(arg), index, &tmp) ? SUCCESS : FAILURE;
    1451             : }
    1452             : /* }}} */
    1453             : 
    1454          77 : ZEND_API int add_index_str(zval *arg, zend_ulong index, zend_string *str) /* {{{ */
    1455             : {
    1456             :         zval tmp;
    1457             : 
    1458          77 :         ZVAL_STR(&tmp, str);
    1459          77 :         return zend_hash_index_update(Z_ARRVAL_P(arg), index, &tmp) ? SUCCESS : FAILURE;
    1460             : }
    1461             : /* }}} */
    1462             : 
    1463         849 : ZEND_API int add_index_string(zval *arg, zend_ulong index, const char *str) /* {{{ */
    1464             : {
    1465             :         zval tmp;
    1466             : 
    1467        1698 :         ZVAL_STRING(&tmp, str);
    1468         849 :         return zend_hash_index_update(Z_ARRVAL_P(arg), index, &tmp) ? SUCCESS : FAILURE;
    1469             : }
    1470             : /* }}} */
    1471             : 
    1472       38883 : ZEND_API int add_index_stringl(zval *arg, zend_ulong index, const char *str, size_t length) /* {{{ */
    1473             : {
    1474             :         zval tmp;
    1475             : 
    1476       77766 :         ZVAL_STRINGL(&tmp, str, length);
    1477       38883 :         return zend_hash_index_update(Z_ARRVAL_P(arg), index, &tmp) ? SUCCESS : FAILURE;
    1478             : }
    1479             : /* }}} */
    1480             : 
    1481       81104 : ZEND_API int add_index_zval(zval *arg, zend_ulong index, zval *value) /* {{{ */
    1482             : {
    1483       81104 :         return zend_hash_index_update(Z_ARRVAL_P(arg), index, value) ? SUCCESS : FAILURE;
    1484             : }
    1485             : /* }}} */
    1486             : 
    1487        3824 : ZEND_API int add_next_index_long(zval *arg, zend_long n) /* {{{ */
    1488             : {
    1489             :         zval tmp;
    1490             : 
    1491        3824 :         ZVAL_LONG(&tmp, n);
    1492        3824 :         return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp) ? SUCCESS : FAILURE;
    1493             : }
    1494             : /* }}} */
    1495             : 
    1496        1066 : ZEND_API int add_next_index_null(zval *arg) /* {{{ */
    1497             : {
    1498             :         zval tmp;
    1499             : 
    1500        1066 :         ZVAL_NULL(&tmp);
    1501        1066 :         return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp) ? SUCCESS : FAILURE;
    1502             : }
    1503             : /* }}} */
    1504             : 
    1505           0 : ZEND_API int add_next_index_bool(zval *arg, int b) /* {{{ */
    1506             : {
    1507             :         zval tmp;
    1508             : 
    1509           0 :         ZVAL_BOOL(&tmp, b);
    1510           0 :         return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp) ? SUCCESS : FAILURE;
    1511             : }
    1512             : /* }}} */
    1513             : 
    1514          16 : ZEND_API int add_next_index_resource(zval *arg, zend_resource *r) /* {{{ */
    1515             : {
    1516             :         zval tmp;
    1517             : 
    1518          16 :         ZVAL_RES(&tmp, r);
    1519          16 :         return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp) ? SUCCESS : FAILURE;
    1520             : }
    1521             : /* }}} */
    1522             : 
    1523           0 : ZEND_API int add_next_index_double(zval *arg, double d) /* {{{ */
    1524             : {
    1525             :         zval tmp;
    1526             : 
    1527           0 :         ZVAL_DOUBLE(&tmp, d);
    1528           0 :         return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp) ? SUCCESS : FAILURE;
    1529             : }
    1530             : /* }}} */
    1531             : 
    1532       14538 : ZEND_API int add_next_index_str(zval *arg, zend_string *str) /* {{{ */
    1533             : {
    1534             :         zval tmp;
    1535             : 
    1536       14538 :         ZVAL_STR(&tmp, str);
    1537       14538 :         return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp) ? SUCCESS : FAILURE;
    1538             : }
    1539             : /* }}} */
    1540             : 
    1541        9773 : ZEND_API int add_next_index_string(zval *arg, const char *str) /* {{{ */
    1542             : {
    1543             :         zval tmp;
    1544             : 
    1545       19546 :         ZVAL_STRING(&tmp, str);
    1546        9773 :         return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp) ? SUCCESS : FAILURE;
    1547             : }
    1548             : /* }}} */
    1549             : 
    1550      128150 : ZEND_API int add_next_index_stringl(zval *arg, const char *str, size_t length) /* {{{ */
    1551             : {
    1552             :         zval tmp;
    1553             : 
    1554      256300 :         ZVAL_STRINGL(&tmp, str, length);
    1555      128150 :         return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp) ? SUCCESS : FAILURE;
    1556             : }
    1557             : /* }}} */
    1558             : 
    1559       48710 : ZEND_API int add_next_index_zval(zval *arg, zval *value) /* {{{ */
    1560             : {
    1561       48710 :         return zend_hash_next_index_insert(Z_ARRVAL_P(arg), value) ? SUCCESS : FAILURE;
    1562             : }
    1563             : /* }}} */
    1564             : 
    1565           0 : ZEND_API zval *add_get_assoc_string_ex(zval *arg, const char *key, uint key_len, const char *str) /* {{{ */
    1566             : {
    1567             :         zval tmp, *ret;
    1568             : 
    1569           0 :         ZVAL_STRING(&tmp, str);
    1570           0 :         ret = zend_symtable_str_update(Z_ARRVAL_P(arg), key, key_len, &tmp);
    1571           0 :         return ret;
    1572             : }
    1573             : /* }}} */
    1574             : 
    1575           0 : ZEND_API zval *add_get_assoc_stringl_ex(zval *arg, const char *key, uint key_len, const char *str, size_t length) /* {{{ */
    1576             : {
    1577             :         zval tmp, *ret;
    1578             : 
    1579           0 :         ZVAL_STRINGL(&tmp, str, length);
    1580           0 :         ret = zend_symtable_str_update(Z_ARRVAL_P(arg), key, key_len, &tmp);
    1581           0 :         return ret;
    1582             : }
    1583             : /* }}} */
    1584             : 
    1585           0 : ZEND_API zval *add_get_index_long(zval *arg, zend_ulong index, zend_long l) /* {{{ */
    1586             : {
    1587             :         zval tmp;
    1588             : 
    1589           0 :         ZVAL_LONG(&tmp, l);
    1590           0 :         return zend_hash_index_update(Z_ARRVAL_P(arg), index, &tmp);
    1591             : }
    1592             : /* }}} */
    1593             : 
    1594           0 : ZEND_API zval *add_get_index_double(zval *arg, zend_ulong index, double d) /* {{{ */
    1595             : {
    1596             :         zval tmp;
    1597             : 
    1598           0 :         ZVAL_DOUBLE(&tmp, d);
    1599           0 :         return zend_hash_index_update(Z_ARRVAL_P(arg), index, &tmp);
    1600             : }
    1601             : /* }}} */
    1602             : 
    1603           0 : ZEND_API zval *add_get_index_str(zval *arg, zend_ulong index, zend_string *str) /* {{{ */
    1604             : {
    1605             :         zval tmp;
    1606             : 
    1607           0 :         ZVAL_STR(&tmp, str);
    1608           0 :         return zend_hash_index_update(Z_ARRVAL_P(arg), index, &tmp);
    1609             : }
    1610             : /* }}} */
    1611             : 
    1612           0 : ZEND_API zval *add_get_index_string(zval *arg, zend_ulong index, const char *str) /* {{{ */
    1613             : {
    1614             :         zval tmp;
    1615             : 
    1616           0 :         ZVAL_STRING(&tmp, str);
    1617           0 :         return zend_hash_index_update(Z_ARRVAL_P(arg), index, &tmp);
    1618             : }
    1619             : /* }}} */
    1620             : 
    1621           0 : ZEND_API zval *add_get_index_stringl(zval *arg, zend_ulong index, const char *str, size_t length) /* {{{ */
    1622             : {
    1623             :         zval tmp;
    1624             : 
    1625           0 :         ZVAL_STRINGL(&tmp, str, length);
    1626           0 :         return zend_hash_index_update(Z_ARRVAL_P(arg), index, &tmp);
    1627             : }
    1628             : /* }}} */
    1629             : 
    1630        2352 : ZEND_API int array_set_zval_key(HashTable *ht, zval *key, zval *value) /* {{{ */
    1631             : {
    1632             :         zval *result;
    1633             : 
    1634        2352 :         switch (Z_TYPE_P(key)) {
    1635             :                 case IS_STRING:
    1636        4502 :                         result = zend_symtable_update(ht, Z_STR_P(key), value);
    1637        2251 :                         break;
    1638             :                 case IS_NULL:
    1639           2 :                         result = zend_symtable_update(ht, ZSTR_EMPTY_ALLOC(), value);
    1640           1 :                         break;
    1641             :                 case IS_RESOURCE:
    1642           0 :                         zend_error(E_NOTICE, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(key), Z_RES_HANDLE_P(key));
    1643           0 :                         result = zend_hash_index_update(ht, Z_RES_HANDLE_P(key), value);
    1644           0 :                         break;
    1645             :                 case IS_FALSE:
    1646           0 :                         result = zend_hash_index_update(ht, 0, value);
    1647           0 :                         break;
    1648             :                 case IS_TRUE:
    1649           0 :                         result = zend_hash_index_update(ht, 1, value);
    1650           0 :                         break;
    1651             :                 case IS_LONG:
    1652          97 :                         result = zend_hash_index_update(ht, Z_LVAL_P(key), value);
    1653          97 :                         break;
    1654             :                 case IS_DOUBLE:
    1655           2 :                         result = zend_hash_index_update(ht, zend_dval_to_lval(Z_DVAL_P(key)), value);
    1656           1 :                         break;
    1657             :                 default:
    1658           2 :                         zend_error(E_WARNING, "Illegal offset type");
    1659           2 :                         result = NULL;
    1660             :         }
    1661             : 
    1662        2352 :         if (result) {
    1663        2350 :                 if (Z_REFCOUNTED_P(result)) {
    1664             :                         Z_ADDREF_P(result);
    1665             :                 }
    1666        2350 :                 return SUCCESS;
    1667             :         } else {
    1668           2 :                 return FAILURE;
    1669             :         }
    1670             : }
    1671             : /* }}} */
    1672             : 
    1673        8923 : ZEND_API int add_property_long_ex(zval *arg, const char *key, size_t key_len, zend_long n) /* {{{ */
    1674             : {
    1675             :         zval tmp;
    1676             :         zval z_key;
    1677             : 
    1678        8923 :         ZVAL_LONG(&tmp, n);
    1679       17846 :         ZVAL_STRINGL(&z_key, key, key_len);
    1680        8923 :         Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, &tmp, NULL);
    1681        8923 :         zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
    1682        8923 :         zval_ptr_dtor(&z_key);
    1683        8923 :         return SUCCESS;
    1684             : }
    1685             : /* }}} */
    1686             : 
    1687         349 : ZEND_API int add_property_bool_ex(zval *arg, const char *key, size_t key_len, zend_long b) /* {{{ */
    1688             : {
    1689             :         zval tmp;
    1690             :         zval z_key;
    1691             : 
    1692         349 :         ZVAL_BOOL(&tmp, b);
    1693         698 :         ZVAL_STRINGL(&z_key, key, key_len);
    1694         349 :         Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, &tmp, NULL);
    1695         349 :         zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
    1696         349 :         zval_ptr_dtor(&z_key);
    1697         349 :         return SUCCESS;
    1698             : }
    1699             : /* }}} */
    1700             : 
    1701          95 : ZEND_API int add_property_null_ex(zval *arg, const char *key, size_t key_len) /* {{{ */
    1702             : {
    1703             :         zval tmp;
    1704             :         zval z_key;
    1705             : 
    1706          95 :         ZVAL_NULL(&tmp);
    1707         190 :         ZVAL_STRINGL(&z_key, key, key_len);
    1708          95 :         Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, &tmp, NULL);
    1709          95 :         zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
    1710          95 :         zval_ptr_dtor(&z_key);
    1711          95 :         return SUCCESS;
    1712             : }
    1713             : /* }}} */
    1714             : 
    1715      393402 : ZEND_API int add_property_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r) /* {{{ */
    1716             : {
    1717             :         zval tmp;
    1718             :         zval z_key;
    1719             : 
    1720      393402 :         ZVAL_RES(&tmp, r);
    1721      786804 :         ZVAL_STRINGL(&z_key, key, key_len);
    1722      393402 :         Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, &tmp, NULL);
    1723      393402 :         zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
    1724      393402 :         zval_ptr_dtor(&z_key);
    1725      393402 :         return SUCCESS;
    1726             : }
    1727             : /* }}} */
    1728             : 
    1729           0 : ZEND_API int add_property_double_ex(zval *arg, const char *key, size_t key_len, double d) /* {{{ */
    1730             : {
    1731             :         zval tmp;
    1732             :         zval z_key;
    1733             : 
    1734           0 :         ZVAL_DOUBLE(&tmp, d);
    1735           0 :         ZVAL_STRINGL(&z_key, key, key_len);
    1736           0 :         Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, &tmp, NULL);
    1737           0 :         zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
    1738           0 :         zval_ptr_dtor(&z_key);
    1739           0 :         return SUCCESS;
    1740             : }
    1741             : /* }}} */
    1742             : 
    1743        1501 : ZEND_API int add_property_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str) /* {{{ */
    1744             : {
    1745             :         zval tmp;
    1746             :         zval z_key;
    1747             : 
    1748        1501 :         ZVAL_STR(&tmp, str);
    1749        3002 :         ZVAL_STRINGL(&z_key, key, key_len);
    1750        1501 :         Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, &tmp, NULL);
    1751        1501 :         zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
    1752        1501 :         zval_ptr_dtor(&z_key);
    1753        1501 :         return SUCCESS;
    1754             : }
    1755             : /* }}} */
    1756             : 
    1757        2734 : ZEND_API int add_property_string_ex(zval *arg, const char *key, size_t key_len, const char *str) /* {{{ */
    1758             : {
    1759             :         zval tmp;
    1760             :         zval z_key;
    1761             : 
    1762        5468 :         ZVAL_STRING(&tmp, str);
    1763        5468 :         ZVAL_STRINGL(&z_key, key, key_len);
    1764        2734 :         Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, &tmp, NULL);
    1765        2734 :         zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
    1766        2734 :         zval_ptr_dtor(&z_key);
    1767        2734 :         return SUCCESS;
    1768             : }
    1769             : /* }}} */
    1770             : 
    1771        6852 : ZEND_API int add_property_stringl_ex(zval *arg, const char *key, size_t key_len, const char *str, size_t length) /* {{{ */
    1772             : {
    1773             :         zval tmp;
    1774             :         zval z_key;
    1775             : 
    1776       13704 :         ZVAL_STRINGL(&tmp, str, length);
    1777       13704 :         ZVAL_STRINGL(&z_key, key, key_len);
    1778        6852 :         Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, &tmp, NULL);
    1779        6852 :         zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
    1780        6852 :         zval_ptr_dtor(&z_key);
    1781        6852 :         return SUCCESS;
    1782             : }
    1783             : /* }}} */
    1784             : 
    1785         716 : ZEND_API int add_property_zval_ex(zval *arg, const char *key, size_t key_len, zval *value) /* {{{ */
    1786             : {
    1787             :         zval z_key;
    1788             : 
    1789        1432 :         ZVAL_STRINGL(&z_key, key, key_len);
    1790         716 :         Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, value, NULL);
    1791         716 :         zval_ptr_dtor(&z_key);
    1792         716 :         return SUCCESS;
    1793             : }
    1794             : /* }}} */
    1795             : 
    1796     1645580 : ZEND_API int zend_startup_module_ex(zend_module_entry *module) /* {{{ */
    1797             : {
    1798             :         size_t name_len;
    1799             :         zend_string *lcname;
    1800             : 
    1801     1645580 :         if (module->module_started) {
    1802           0 :                 return SUCCESS;
    1803             :         }
    1804     1645580 :         module->module_started = 1;
    1805             : 
    1806             :         /* Check module dependencies */
    1807     1645580 :         if (module->deps) {
    1808      493584 :                 const zend_module_dep *dep = module->deps;
    1809             : 
    1810     1739296 :                 while (dep->name) {
    1811      752128 :                         if (dep->type == MODULE_DEP_REQUIRED) {
    1812             :                                 zend_module_entry *req_mod;
    1813             : 
    1814      540592 :                                 name_len = strlen(dep->name);
    1815      540592 :                                 lcname = zend_string_alloc(name_len, 0);
    1816      540592 :                                 zend_str_tolower_copy(ZSTR_VAL(lcname), dep->name, name_len);
    1817             : 
    1818      540592 :                                 if ((req_mod = zend_hash_find_ptr(&module_registry, lcname)) == NULL || !req_mod->module_started) {
    1819             :                                         zend_string_free(lcname);
    1820             :                                         /* TODO: Check version relationship */
    1821           0 :                                         zend_error(E_CORE_WARNING, "Cannot load module '%s' because required module '%s' is not loaded", module->name, dep->name);
    1822           0 :                                         module->module_started = 0;
    1823           0 :                                         return FAILURE;
    1824             :                                 }
    1825             :                                 zend_string_free(lcname);
    1826             :                         }
    1827      752128 :                         ++dep;
    1828             :                 }
    1829             :         }
    1830             : 
    1831             :         /* Initialize module globals */
    1832     1645580 :         if (module->globals_size) {
    1833             : #ifdef ZTS
    1834             :                 ts_allocate_id(module->globals_id_ptr, module->globals_size, (ts_allocate_ctor) module->globals_ctor, (ts_allocate_dtor) module->globals_dtor);
    1835             : #else
    1836      799136 :                 if (module->globals_ctor) {
    1837      775632 :                         module->globals_ctor(module->globals_ptr);
    1838             :                 }
    1839             : #endif
    1840             :         }
    1841     1645580 :         if (module->module_startup_func) {
    1842     1598572 :                 EG(current_module) = module;
    1843     1598572 :                 if (module->module_startup_func(module->type, module->module_number)==FAILURE) {
    1844           0 :                         zend_error_noreturn(E_CORE_ERROR,"Unable to start %s module", module->name);
    1845             :                         EG(current_module) = NULL;
    1846             :                         return FAILURE;
    1847             :                 }
    1848     1598572 :                 EG(current_module) = NULL;
    1849             :         }
    1850     1645580 :         return SUCCESS;
    1851             : }
    1852             : /* }}} */
    1853             : 
    1854     1622252 : static int zend_startup_module_zval(zval *zv) /* {{{ */
    1855             : {
    1856     1622252 :         zend_module_entry *module = Z_PTR_P(zv);
    1857             : 
    1858     1622252 :         return zend_startup_module_ex(module);
    1859             : }
    1860             : /* }}} */
    1861             : 
    1862       23504 : static void zend_sort_modules(void *base, size_t count, size_t siz, compare_func_t compare, swap_func_t swp) /* {{{ */
    1863             : {
    1864       23504 :         Bucket *b1 = base;
    1865             :         Bucket *b2;
    1866       23504 :         Bucket *end = b1 + count;
    1867             :         Bucket tmp;
    1868             :         zend_module_entry *m, *r;
    1869             : 
    1870     1669260 :         while (b1 < end) {
    1871             : try_again:
    1872     1810284 :                 m = (zend_module_entry*)Z_PTR(b1->val);
    1873     1810284 :                 if (!m->module_started && m->deps) {
    1874      681616 :                         const zend_module_dep *dep = m->deps;
    1875     2162368 :                         while (dep->name) {
    1876      987168 :                                 if (dep->type == MODULE_DEP_REQUIRED || dep->type == MODULE_DEP_OPTIONAL) {
    1877      963664 :                                         b2 = b1 + 1;
    1878    25329516 :                                         while (b2 < end) {
    1879    23590220 :                                                 r = (zend_module_entry*)Z_PTR(b2->val);
    1880    23590220 :                                                 if (strcasecmp(dep->name, r->name) == 0) {
    1881      188032 :                                                         tmp = *b1;
    1882      188032 :                                                         *b1 = *b2;
    1883      188032 :                                                         *b2 = tmp;
    1884      188032 :                                                         goto try_again;
    1885             :                                                 }
    1886    23402188 :                                                 b2++;
    1887             :                                         }
    1888             :                                 }
    1889      799136 :                                 dep++;
    1890             :                         }
    1891             :                 }
    1892     1622252 :                 b1++;
    1893             :         }
    1894       23504 : }
    1895             : /* }}} */
    1896             : 
    1897       23504 : ZEND_API void zend_collect_module_handlers(void) /* {{{ */
    1898             : {
    1899             :         zend_module_entry *module;
    1900       23504 :         int startup_count = 0;
    1901       23504 :         int shutdown_count = 0;
    1902       23504 :         int post_deactivate_count = 0;
    1903             :         zend_class_entry *ce;
    1904       23504 :         int class_count = 0;
    1905             : 
    1906             :         /* Collect extensions with request startup/shutdown handlers */
    1907     3314664 :         ZEND_HASH_FOREACH_PTR(&module_registry, module) {
    1908     1645580 :                 if (module->request_startup_func) {
    1909      399631 :                         startup_count++;
    1910             :                 }
    1911     1645580 :                 if (module->request_shutdown_func) {
    1912      493647 :                         shutdown_count++;
    1913             :                 }
    1914     1645580 :                 if (module->post_deactivate_func) {
    1915       46832 :                         post_deactivate_count++;
    1916             :                 }
    1917             :         } ZEND_HASH_FOREACH_END();
    1918       23504 :         module_request_startup_handlers = (zend_module_entry**)malloc(
    1919             :             sizeof(zend_module_entry*) *
    1920       47008 :                 (startup_count + 1 +
    1921       23504 :                  shutdown_count + 1 +
    1922       23504 :                  post_deactivate_count + 1));
    1923       23504 :         module_request_startup_handlers[startup_count] = NULL;
    1924       23504 :         module_request_shutdown_handlers = module_request_startup_handlers + startup_count + 1;
    1925       23504 :         module_request_shutdown_handlers[shutdown_count] = NULL;
    1926       23504 :         module_post_deactivate_handlers = module_request_shutdown_handlers + shutdown_count + 1;
    1927       23504 :         module_post_deactivate_handlers[post_deactivate_count] = NULL;
    1928       23504 :         startup_count = 0;
    1929             : 
    1930     3314664 :         ZEND_HASH_FOREACH_PTR(&module_registry, module) {
    1931     1645580 :                 if (module->request_startup_func) {
    1932      399631 :                         module_request_startup_handlers[startup_count++] = module;
    1933             :                 }
    1934     1645580 :                 if (module->request_shutdown_func) {
    1935      493647 :                         module_request_shutdown_handlers[--shutdown_count] = module;
    1936             :                 }
    1937     1645580 :                 if (module->post_deactivate_func) {
    1938       46832 :                         module_post_deactivate_handlers[--post_deactivate_count] = module;
    1939             :                 }
    1940             :         } ZEND_HASH_FOREACH_END();
    1941             : 
    1942             :         /* Collect internal classes with static members */
    1943     9096048 :         ZEND_HASH_FOREACH_PTR(CG(class_table), ce) {
    1944     9072544 :                 if (ce->type == ZEND_INTERNAL_CLASS &&
    1945     4536272 :                     ce->default_static_members_count > 0) {
    1946           0 :                     class_count++;
    1947             :                 }
    1948             :         } ZEND_HASH_FOREACH_END();
    1949             : 
    1950       23504 :         class_cleanup_handlers = (zend_class_entry**)malloc(
    1951             :                 sizeof(zend_class_entry*) *
    1952       23504 :                 (class_count + 1));
    1953       23504 :         class_cleanup_handlers[class_count] = NULL;
    1954             : 
    1955       23504 :         if (class_count) {
    1956           0 :                 ZEND_HASH_FOREACH_PTR(CG(class_table), ce) {
    1957           0 :                         if (ce->type == ZEND_INTERNAL_CLASS &&
    1958           0 :                             ce->default_static_members_count > 0) {
    1959           0 :                             class_cleanup_handlers[--class_count] = ce;
    1960             :                         }
    1961             :                 } ZEND_HASH_FOREACH_END();
    1962             :         }
    1963       23504 : }
    1964             : /* }}} */
    1965             : 
    1966       23504 : ZEND_API int zend_startup_modules(void) /* {{{ */
    1967             : {
    1968       23504 :         zend_hash_sort_ex(&module_registry, zend_sort_modules, NULL, 0);
    1969       23504 :         zend_hash_apply(&module_registry, zend_startup_module_zval);
    1970       23504 :         return SUCCESS;
    1971             : }
    1972             : /* }}} */
    1973             : 
    1974       23544 : ZEND_API void zend_destroy_modules(void) /* {{{ */
    1975             : {
    1976       23544 :         free(class_cleanup_handlers);
    1977       23544 :         free(module_request_startup_handlers);
    1978       23544 :         zend_hash_graceful_reverse_destroy(&module_registry);
    1979       23544 : }
    1980             : /* }}} */
    1981             : 
    1982     1645580 : ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module) /* {{{ */
    1983             : {
    1984             :         size_t name_len;
    1985             :         zend_string *lcname;
    1986             :         zend_module_entry *module_ptr;
    1987             : 
    1988     1645580 :         if (!module) {
    1989           0 :                 return NULL;
    1990             :         }
    1991             : 
    1992             : #if 0
    1993             :         zend_printf("%s: Registering module %d\n", module->name, module->module_number);
    1994             : #endif
    1995             : 
    1996             :         /* Check module dependencies */
    1997     1645580 :         if (module->deps) {
    1998      493584 :                 const zend_module_dep *dep = module->deps;
    1999             : 
    2000     1739296 :                 while (dep->name) {
    2001      752128 :                         if (dep->type == MODULE_DEP_CONFLICTS) {
    2002       23504 :                                 name_len = strlen(dep->name);
    2003       23504 :                                 lcname = zend_string_alloc(name_len, 0);
    2004       23504 :                                 zend_str_tolower_copy(ZSTR_VAL(lcname), dep->name, name_len);
    2005             : 
    2006       23504 :                                 if (zend_hash_exists(&module_registry, lcname) || zend_get_extension(dep->name)) {
    2007             :                                         zend_string_free(lcname);
    2008             :                                         /* TODO: Check version relationship */
    2009           0 :                                         zend_error(E_CORE_WARNING, "Cannot load module '%s' because conflicting module '%s' is already loaded", module->name, dep->name);
    2010           0 :                                         return NULL;
    2011             :                                 }
    2012             :                                 zend_string_free(lcname);
    2013             :                         }
    2014      752128 :                         ++dep;
    2015             :                 }
    2016             :         }
    2017             : 
    2018     1645580 :         name_len = strlen(module->name);
    2019     1645580 :         lcname = zend_string_alloc(name_len, 1);
    2020     1645580 :         zend_str_tolower_copy(ZSTR_VAL(lcname), module->name, name_len);
    2021             : 
    2022     1645580 :         if ((module_ptr = zend_hash_add_mem(&module_registry, lcname, module, sizeof(zend_module_entry))) == NULL) {
    2023           0 :                 zend_error(E_CORE_WARNING, "Module '%s' already loaded", module->name);
    2024             :                 zend_string_release(lcname);
    2025           0 :                 return NULL;
    2026             :         }
    2027             :         zend_string_release(lcname);
    2028     1645580 :         module = module_ptr;
    2029     1645580 :         EG(current_module) = module;
    2030             : 
    2031     1645580 :         if (module->functions && zend_register_functions(NULL, module->functions, NULL, module->type)==FAILURE) {
    2032           0 :                 EG(current_module) = NULL;
    2033           0 :                 zend_error(E_CORE_WARNING,"%s: Unable to register functions, unable to load", module->name);
    2034           0 :                 return NULL;
    2035             :         }
    2036             : 
    2037     1645580 :         EG(current_module) = NULL;
    2038     1645580 :         return module;
    2039             : }
    2040             : /* }}} */
    2041             : 
    2042     1622076 : ZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *module) /* {{{ */
    2043             : {
    2044     1622076 :         module->module_number = zend_next_free_module();
    2045     1622076 :         module->type = MODULE_PERSISTENT;
    2046     1622076 :         return zend_register_module_ex(module);
    2047             : }
    2048             : /* }}} */
    2049             : 
    2050     2957088 : ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, const zend_function *fptr, int error_type) /* {{{ */
    2051             : {
    2052             :         char lcname[16];
    2053             :         size_t name_len;
    2054             : 
    2055             :         /* we don't care if the function name is longer, in fact lowercasing only
    2056             :          * the beginning of the name speeds up the check process */
    2057     2957088 :         name_len = ZSTR_LEN(fptr->common.function_name);
    2058     2957088 :         zend_str_tolower_copy(lcname, ZSTR_VAL(fptr->common.function_name), MIN(name_len, sizeof(lcname)-1));
    2059     2957088 :         lcname[sizeof(lcname)-1] = '\0'; /* zend_str_tolower_copy won't necessarily set the zero byte */
    2060             : 
    2061     2957088 :         if (name_len == sizeof(ZEND_DESTRUCTOR_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_DESTRUCTOR_FUNC_NAME, sizeof(ZEND_DESTRUCTOR_FUNC_NAME) - 1) && fptr->common.num_args != 0) {
    2062           1 :                 zend_error(error_type, "Destructor %s::%s() cannot take arguments", ZSTR_VAL(ce->name), ZEND_DESTRUCTOR_FUNC_NAME);
    2063     2957087 :         } else if (name_len == sizeof(ZEND_CLONE_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME) - 1) && fptr->common.num_args != 0) {
    2064           1 :                 zend_error(error_type, "Method %s::%s() cannot accept any arguments", ZSTR_VAL(ce->name), ZEND_CLONE_FUNC_NAME);
    2065     2957161 :         } else if (name_len == sizeof(ZEND_GET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME) - 1)) {
    2066          77 :                 if (fptr->common.num_args != 1) {
    2067           1 :                         zend_error(error_type, "Method %s::%s() must take exactly 1 argument", ZSTR_VAL(ce->name), ZEND_GET_FUNC_NAME);
    2068          76 :                 } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1)) {
    2069           1 :                         zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ZSTR_VAL(ce->name), ZEND_GET_FUNC_NAME);
    2070             :                 }
    2071     2957068 :         } else if (name_len == sizeof(ZEND_SET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME) - 1)) {
    2072          63 :                 if (fptr->common.num_args != 2) {
    2073           2 :                         zend_error(error_type, "Method %s::%s() must take exactly 2 arguments", ZSTR_VAL(ce->name), ZEND_SET_FUNC_NAME);
    2074         121 :                 } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1) || ARG_SHOULD_BE_SENT_BY_REF(fptr, 2)) {
    2075           2 :                         zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ZSTR_VAL(ce->name), ZEND_SET_FUNC_NAME);
    2076             :                 }
    2077     2956962 :         } else if (name_len == sizeof(ZEND_UNSET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_UNSET_FUNC_NAME, sizeof(ZEND_UNSET_FUNC_NAME) - 1)) {
    2078          18 :                 if (fptr->common.num_args != 1) {
    2079           1 :                         zend_error(error_type, "Method %s::%s() must take exactly 1 argument", ZSTR_VAL(ce->name), ZEND_UNSET_FUNC_NAME);
    2080          17 :                 } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1)) {
    2081           1 :                         zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ZSTR_VAL(ce->name), ZEND_UNSET_FUNC_NAME);
    2082             :                 }
    2083     2956946 :         } else if (name_len == sizeof(ZEND_ISSET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME) - 1)) {
    2084          20 :                 if (fptr->common.num_args != 1) {
    2085           1 :                         zend_error(error_type, "Method %s::%s() must take exactly 1 argument", ZSTR_VAL(ce->name), ZEND_ISSET_FUNC_NAME);
    2086          19 :                 } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1)) {
    2087           1 :                         zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ZSTR_VAL(ce->name), ZEND_ISSET_FUNC_NAME);
    2088             :                 }
    2089     2980486 :         } else if (name_len == sizeof(ZEND_CALL_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME) - 1)) {
    2090       23581 :                 if (fptr->common.num_args != 2) {
    2091           1 :                         zend_error(error_type, "Method %s::%s() must take exactly 2 arguments", ZSTR_VAL(ce->name), ZEND_CALL_FUNC_NAME);
    2092       47159 :                 } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1) || ARG_SHOULD_BE_SENT_BY_REF(fptr, 2)) {
    2093           2 :                         zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ZSTR_VAL(ce->name), ZEND_CALL_FUNC_NAME);
    2094             :                 }
    2095     2934869 :         } else if (name_len == sizeof(ZEND_CALLSTATIC_FUNC_NAME) - 1 &&
    2096        1509 :                 !memcmp(lcname, ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1)
    2097             :         ) {
    2098          33 :                 if (fptr->common.num_args != 2) {
    2099           0 :                         zend_error(error_type, "Method %s::__callStatic() must take exactly 2 arguments", ZSTR_VAL(ce->name));
    2100          66 :                 } else if (ARG_SHOULD_BE_SENT_BY_REF(fptr, 1) || ARG_SHOULD_BE_SENT_BY_REF(fptr, 2)) {
    2101           0 :                         zend_error(error_type, "Method %s::__callStatic() cannot take arguments by reference", ZSTR_VAL(ce->name));
    2102             :                 }
    2103     3971308 :         } else if (name_len == sizeof(ZEND_TOSTRING_FUNC_NAME) - 1 &&
    2104     1038014 :                 !memcmp(lcname, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && fptr->common.num_args != 0
    2105             :         ) {
    2106           1 :                 zend_error(error_type, "Method %s::%s() cannot take arguments", ZSTR_VAL(ce->name), ZEND_TOSTRING_FUNC_NAME);
    2107     4934130 :         } else if (name_len == sizeof(ZEND_DEBUGINFO_FUNC_NAME) - 1 &&
    2108     2000837 :                 !memcmp(lcname, ZEND_DEBUGINFO_FUNC_NAME, sizeof(ZEND_DEBUGINFO_FUNC_NAME)-1) && fptr->common.num_args != 0) {
    2109           0 :                 zend_error(error_type, "Method %s::%s() cannot take arguments", ZSTR_VAL(ce->name), ZEND_DEBUGINFO_FUNC_NAME);
    2110             :         }
    2111     2957072 : }
    2112             : /* }}} */
    2113             : 
    2114             : /* registers all functions in *library_functions in the function hash */
    2115     5476449 : ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_function_entry *functions, HashTable *function_table, int type) /* {{{ */
    2116             : {
    2117     5476449 :         const zend_function_entry *ptr = functions;
    2118             :         zend_function function, *reg_function;
    2119     5476449 :         zend_internal_function *internal_function = (zend_internal_function *)&function;
    2120     5476449 :         int count=0, unload=0;
    2121     5476449 :         HashTable *target_function_table = function_table;
    2122             :         int error_type;
    2123     5476449 :         zend_function *ctor = NULL, *dtor = NULL, *clone = NULL, *__get = NULL, *__set = NULL, *__unset = NULL, *__isset = NULL, *__call = NULL, *__callstatic = NULL, *__tostring = NULL, *__debugInfo = NULL;
    2124             :         zend_string *lowercase_name;
    2125             :         size_t fname_len;
    2126     5476449 :         const char *lc_class_name = NULL;
    2127     5476449 :         size_t class_name_len = 0;
    2128             : 
    2129     5476449 :         if (type==MODULE_PERSISTENT) {
    2130     5476449 :                 error_type = E_CORE_WARNING;
    2131             :         } else {
    2132           0 :                 error_type = E_WARNING;
    2133             :         }
    2134             : 
    2135     5476449 :         if (!target_function_table) {
    2136     1621793 :                 target_function_table = CG(function_table);
    2137             :         }
    2138     5476449 :         internal_function->type = ZEND_INTERNAL_FUNCTION;
    2139     5476449 :         internal_function->module = EG(current_module);
    2140     5476449 :         memset(internal_function->reserved, 0, ZEND_MAX_RESERVED_RESOURCES * sizeof(void*));
    2141             : 
    2142     5476449 :         if (scope) {
    2143     3854656 :                 class_name_len = ZSTR_LEN(scope->name);
    2144     7709312 :                 if ((lc_class_name = zend_memrchr(ZSTR_VAL(scope->name), '\\', class_name_len))) {
    2145           0 :                         ++lc_class_name;
    2146           0 :                         class_name_len -= (lc_class_name - ZSTR_VAL(scope->name));
    2147           0 :                         lc_class_name = zend_str_tolower_dup(lc_class_name, class_name_len);
    2148             :                 } else {
    2149     3854656 :                         lc_class_name = zend_str_tolower_dup(ZSTR_VAL(scope->name), class_name_len);
    2150             :                 }
    2151             :         }
    2152             : 
    2153   101278824 :         while (ptr->fname) {
    2154    90325926 :                 fname_len = strlen(ptr->fname);
    2155    90325926 :                 internal_function->handler = ptr->handler;
    2156   180651852 :                 internal_function->function_name = zend_new_interned_string(zend_string_init(ptr->fname, fname_len, 1));
    2157    90325926 :                 internal_function->scope = scope;
    2158    90325926 :                 internal_function->prototype = NULL;
    2159    90325926 :                 if (ptr->flags) {
    2160    24890736 :                         if (!(ptr->flags & ZEND_ACC_PPP_MASK)) {
    2161      775632 :                                 if (ptr->flags != ZEND_ACC_DEPRECATED || scope) {
    2162           0 :                                         zend_error(error_type, "Invalid access level for %s%s%s() - access must be exactly one of public, protected or private", scope ? ZSTR_VAL(scope->name) : "", scope ? "::" : "", ptr->fname);
    2163             :                                 }
    2164      775632 :                                 internal_function->fn_flags = ZEND_ACC_PUBLIC | ptr->flags;
    2165             :                         } else {
    2166    24115104 :                                 internal_function->fn_flags = ptr->flags;
    2167             :                         }
    2168             :                 } else {
    2169    65435190 :                         internal_function->fn_flags = ZEND_ACC_PUBLIC;
    2170             :                 }
    2171    90325926 :                 if (ptr->arg_info) {
    2172    88093046 :                         zend_internal_function_info *info = (zend_internal_function_info*)ptr->arg_info;
    2173             : 
    2174    88093046 :                         internal_function->arg_info = (zend_internal_arg_info*)ptr->arg_info+1;
    2175    88093046 :                         internal_function->num_args = ptr->num_args;
    2176             :                         /* Currently you cannot denote that the function can accept less arguments than num_args */
    2177    88093046 :                         if (info->required_num_args == (zend_uintptr_t)-1) {
    2178    31471921 :                                 internal_function->required_num_args = ptr->num_args;
    2179             :                         } else {
    2180    56621125 :                                 internal_function->required_num_args = info->required_num_args;
    2181             :                         }
    2182    88093046 :                         if (info->return_reference) {
    2183           0 :                                 internal_function->fn_flags |= ZEND_ACC_RETURN_REFERENCE;
    2184             :                         }
    2185    88093046 :                         if (ptr->arg_info[ptr->num_args].is_variadic) {
    2186      963664 :                                 internal_function->fn_flags |= ZEND_ACC_VARIADIC;
    2187             :                                 /* Don't count the variadic argument */
    2188      963664 :                                 internal_function->num_args--;
    2189             :                         }
    2190    88093046 :                         if (info->type_hint) {
    2191           0 :                                 if (info->class_name) {
    2192             :                                         ZEND_ASSERT(info->type_hint == IS_OBJECT);
    2193           0 :                                         if (!scope && (!strcasecmp(info->class_name, "self") || !strcasecmp(info->class_name, "parent"))) {
    2194           0 :                                                 zend_error_noreturn(E_CORE_ERROR, "Cannot declare a return type of %s outside of a class scope", info->class_name);
    2195             :                                         }
    2196             :                                 }
    2197             : 
    2198           0 :                                 internal_function->fn_flags |= ZEND_ACC_HAS_RETURN_TYPE;
    2199             :                         }
    2200             :                 } else {
    2201     2232880 :                         internal_function->arg_info = NULL;
    2202     2232880 :                         internal_function->num_args = 0;
    2203     2232880 :                         internal_function->required_num_args = 0;
    2204             :                 }
    2205    90325926 :                 zend_set_function_arg_flags((zend_function*)internal_function);
    2206    90325926 :                 if (ptr->flags & ZEND_ACC_ABSTRACT) {
    2207     1151696 :                         if (scope) {
    2208             :                                 /* This is a class that must be abstract itself. Here we set the check info. */
    2209     1151696 :                                 scope->ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
    2210     1151696 :                                 if (!(scope->ce_flags & ZEND_ACC_INTERFACE)) {
    2211             :                                         /* Since the class is not an interface it needs to be declared as a abstract class. */
    2212             :                                         /* Since here we are handling internal functions only we can add the keyword flag. */
    2213             :                                         /* This time we set the flag for the keyword 'abstract'. */
    2214      258544 :                                         scope->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
    2215             :                                 }
    2216             :                         }
    2217     1151696 :                         if (ptr->flags & ZEND_ACC_STATIC && (!scope || !(scope->ce_flags & ZEND_ACC_INTERFACE))) {
    2218           0 :                                 zend_error(error_type, "Static function %s%s%s() cannot be abstract", scope ? ZSTR_VAL(scope->name) : "", scope ? "::" : "", ptr->fname);
    2219             :                         }
    2220             :                 } else {
    2221    89174230 :                         if (scope && (scope->ce_flags & ZEND_ACC_INTERFACE)) {
    2222           0 :                                 efree((char*)lc_class_name);
    2223           0 :                                 zend_error(error_type, "Interface %s cannot contain non abstract method %s()", ZSTR_VAL(scope->name), ptr->fname);
    2224           0 :                                 return FAILURE;
    2225             :                         }
    2226    89174230 :                         if (!internal_function->handler) {
    2227           0 :                                 if (scope) {
    2228           0 :                                         efree((char*)lc_class_name);
    2229             :                                 }
    2230           0 :                                 zend_error(error_type, "Method %s%s%s() cannot be a NULL function", scope ? ZSTR_VAL(scope->name) : "", scope ? "::" : "", ptr->fname);
    2231           0 :                                 zend_unregister_functions(functions, count, target_function_table);
    2232           0 :                                 return FAILURE;
    2233             :                         }
    2234             :                 }
    2235    90325926 :                 lowercase_name = zend_string_alloc(fname_len, 1);
    2236    90325926 :                 zend_str_tolower_copy(ZSTR_VAL(lowercase_name), ptr->fname, fname_len);
    2237    90325926 :                 lowercase_name = zend_new_interned_string(lowercase_name);
    2238    90325926 :                 reg_function = malloc(sizeof(zend_internal_function));
    2239    90325926 :                 memcpy(reg_function, &function, sizeof(zend_internal_function));
    2240    90325926 :                 if (zend_hash_add_ptr(target_function_table, lowercase_name, reg_function) == NULL) {
    2241           0 :                         unload=1;
    2242           0 :                         free(reg_function);
    2243             :                         zend_string_release(lowercase_name);
    2244           0 :                         break;
    2245             :                 }
    2246             : 
    2247             :                 /* If types of arguments have to be checked */
    2248    90325926 :                 if (reg_function->common.arg_info && reg_function->common.num_args) {
    2249             :                         uint32_t i;
    2250   200863279 :                         for (i = 0; i < reg_function->common.num_args; i++) {
    2251   271093244 :                                 if (reg_function->common.arg_info[i].class_name ||
    2252   134183390 :                                     reg_function->common.arg_info[i].type_hint) {
    2253     3102528 :                                     reg_function->common.fn_flags |= ZEND_ACC_HAS_TYPE_HINTS;
    2254     3102528 :                                         break;
    2255             :                                 }
    2256             :                         }
    2257             :                 }
    2258             : 
    2259    90325926 :                 if (scope) {
    2260             :                         /* Look for ctor, dtor, clone
    2261             :                          * If it's an old-style constructor, store it only if we don't have
    2262             :                          * a constructor already.
    2263             :                          */
    2264    38664080 :                         if ((fname_len == class_name_len) && !ctor && !memcmp(ZSTR_VAL(lowercase_name), lc_class_name, class_name_len+1)) {
    2265      164528 :                                 ctor = reg_function;
    2266    40332864 :                         } else if (zend_string_equals_literal(lowercase_name, ZEND_CONSTRUCTOR_FUNC_NAME)) {
    2267     1997840 :                                 ctor = reg_function;
    2268    36407696 :                         } else if (zend_string_equals_literal(lowercase_name, ZEND_DESTRUCTOR_FUNC_NAME)) {
    2269       70512 :                                 dtor = reg_function;
    2270       70512 :                                 if (internal_function->num_args) {
    2271           0 :                                         zend_error(error_type, "Destructor %s::%s() cannot take arguments", ZSTR_VAL(scope->name), ptr->fname);
    2272             :                                 }
    2273    36501712 :                         } else if (zend_string_equals_literal(lowercase_name, ZEND_CLONE_FUNC_NAME)) {
    2274      235040 :                                 clone = reg_function;
    2275    36055136 :                         } else if (zend_string_equals_literal(lowercase_name, ZEND_CALL_FUNC_NAME)) {
    2276       23504 :                                 __call = reg_function;
    2277    36008128 :                         } else if (zend_string_equals_literal(lowercase_name, ZEND_CALLSTATIC_FUNC_NAME)) {
    2278           0 :                                 __callstatic = reg_function;
    2279    36454704 :                         } else if (zend_string_equals_literal(lowercase_name, ZEND_TOSTRING_FUNC_NAME)) {
    2280      446576 :                                 __tostring = reg_function;
    2281    35561552 :                         } else if (zend_string_equals_literal(lowercase_name, ZEND_GET_FUNC_NAME)) {
    2282           0 :                                 __get = reg_function;
    2283           0 :                                 scope->ce_flags |= ZEND_ACC_USE_GUARDS;
    2284    35561552 :                         } else if (zend_string_equals_literal(lowercase_name, ZEND_SET_FUNC_NAME)) {
    2285           0 :                                 __set = reg_function;
    2286           0 :                                 scope->ce_flags |= ZEND_ACC_USE_GUARDS;
    2287    35561552 :                         } else if (zend_string_equals_literal(lowercase_name, ZEND_UNSET_FUNC_NAME)) {
    2288           0 :                                 __unset = reg_function;
    2289           0 :                                 scope->ce_flags |= ZEND_ACC_USE_GUARDS;
    2290    35561552 :                         } else if (zend_string_equals_literal(lowercase_name, ZEND_ISSET_FUNC_NAME)) {
    2291           0 :                                 __isset = reg_function;
    2292           0 :                                 scope->ce_flags |= ZEND_ACC_USE_GUARDS;
    2293    35561552 :                         } else if (zend_string_equals_literal(lowercase_name, ZEND_DEBUGINFO_FUNC_NAME)) {
    2294           0 :                                 __debugInfo = reg_function;
    2295             :                         } else {
    2296    35561552 :                                 reg_function = NULL;
    2297             :                         }
    2298    38499552 :                         if (reg_function) {
    2299     2938000 :                                 zend_check_magic_method_implementation(scope, reg_function, error_type);
    2300             :                         }
    2301             :                 }
    2302    90325926 :                 ptr++;
    2303    90325926 :                 count++;
    2304             :                 zend_string_release(lowercase_name);
    2305             :         }
    2306     5476449 :         if (unload) { /* before unloading, display all remaining bad function in the module */
    2307           0 :                 if (scope) {
    2308           0 :                         efree((char*)lc_class_name);
    2309             :                 }
    2310           0 :                 while (ptr->fname) {
    2311           0 :                         fname_len = strlen(ptr->fname);
    2312           0 :                         lowercase_name = zend_string_alloc(fname_len, 0);
    2313           0 :                         zend_str_tolower_copy(ZSTR_VAL(lowercase_name), ptr->fname, fname_len);
    2314           0 :                         if (zend_hash_exists(target_function_table, lowercase_name)) {
    2315           0 :                                 zend_error(error_type, "Function registration failed - duplicate name - %s%s%s", scope ? ZSTR_VAL(scope->name) : "", scope ? "::" : "", ptr->fname);
    2316             :                         }
    2317             :                         zend_string_free(lowercase_name);
    2318           0 :                         ptr++;
    2319             :                 }
    2320           0 :                 zend_unregister_functions(functions, count, target_function_table);
    2321           0 :                 return FAILURE;
    2322             :         }
    2323     5476449 :         if (scope) {
    2324     3854656 :                 scope->constructor = ctor;
    2325     3854656 :                 scope->destructor = dtor;
    2326     3854656 :                 scope->clone = clone;
    2327     3854656 :                 scope->__call = __call;
    2328     3854656 :                 scope->__callstatic = __callstatic;
    2329     3854656 :                 scope->__tostring = __tostring;
    2330     3854656 :                 scope->__get = __get;
    2331     3854656 :                 scope->__set = __set;
    2332     3854656 :                 scope->__unset = __unset;
    2333     3854656 :                 scope->__isset = __isset;
    2334     3854656 :                 scope->__debugInfo = __debugInfo;
    2335     3854656 :                 if (ctor) {
    2336     2162368 :                         ctor->common.fn_flags |= ZEND_ACC_CTOR;
    2337     2162368 :                         if (ctor->common.fn_flags & ZEND_ACC_STATIC) {
    2338           0 :                                 zend_error(error_type, "Constructor %s::%s() cannot be static", ZSTR_VAL(scope->name), ZSTR_VAL(ctor->common.function_name));
    2339             :                         }
    2340     2162368 :                         ctor->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
    2341             :                 }
    2342     3854656 :                 if (dtor) {
    2343       70512 :                         dtor->common.fn_flags |= ZEND_ACC_DTOR;
    2344       70512 :                         if (dtor->common.fn_flags & ZEND_ACC_STATIC) {
    2345           0 :                                 zend_error(error_type, "Destructor %s::%s() cannot be static", ZSTR_VAL(scope->name), ZSTR_VAL(dtor->common.function_name));
    2346             :                         }
    2347       70512 :                         dtor->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
    2348             :                 }
    2349     3854656 :                 if (clone) {
    2350      235040 :                         clone->common.fn_flags |= ZEND_ACC_CLONE;
    2351      235040 :                         if (clone->common.fn_flags & ZEND_ACC_STATIC) {
    2352           0 :                                 zend_error(error_type, "Constructor %s::%s() cannot be static", ZSTR_VAL(scope->name), ZSTR_VAL(clone->common.function_name));
    2353             :                         }
    2354      235040 :                         clone->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
    2355             :                 }
    2356     3854656 :                 if (__call) {
    2357       23504 :                         if (__call->common.fn_flags & ZEND_ACC_STATIC) {
    2358           0 :                                 zend_error(error_type, "Method %s::%s() cannot be static", ZSTR_VAL(scope->name), ZSTR_VAL(__call->common.function_name));
    2359             :                         }
    2360       23504 :                         __call->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
    2361             :                 }
    2362     3854656 :                 if (__callstatic) {
    2363           0 :                         if (!(__callstatic->common.fn_flags & ZEND_ACC_STATIC)) {
    2364           0 :                                 zend_error(error_type, "Method %s::%s() must be static", ZSTR_VAL(scope->name), ZSTR_VAL(__callstatic->common.function_name));
    2365             :                         }
    2366           0 :                         __callstatic->common.fn_flags |= ZEND_ACC_STATIC;
    2367             :                 }
    2368     3854656 :                 if (__tostring) {
    2369      446576 :                         if (__tostring->common.fn_flags & ZEND_ACC_STATIC) {
    2370           0 :                                 zend_error(error_type, "Method %s::%s() cannot be static", ZSTR_VAL(scope->name), ZSTR_VAL(__tostring->common.function_name));
    2371             :                         }
    2372      446576 :                         __tostring->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
    2373             :                 }
    2374     3854656 :                 if (__get) {
    2375           0 :                         if (__get->common.fn_flags & ZEND_ACC_STATIC) {
    2376           0 :                                 zend_error(error_type, "Method %s::%s() cannot be static", ZSTR_VAL(scope->name), ZSTR_VAL(__get->common.function_name));
    2377             :                         }
    2378           0 :                         __get->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
    2379             :                 }
    2380     3854656 :                 if (__set) {
    2381           0 :                         if (__set->common.fn_flags & ZEND_ACC_STATIC) {
    2382           0 :                                 zend_error(error_type, "Method %s::%s() cannot be static", ZSTR_VAL(scope->name), ZSTR_VAL(__set->common.function_name));
    2383             :                         }
    2384           0 :                         __set->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
    2385             :                 }
    2386     3854656 :                 if (__unset) {
    2387           0 :                         if (__unset->common.fn_flags & ZEND_ACC_STATIC) {
    2388           0 :                                 zend_error(error_type, "Method %s::%s() cannot be static", ZSTR_VAL(scope->name), ZSTR_VAL(__unset->common.function_name));
    2389             :                         }
    2390           0 :                         __unset->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
    2391             :                 }
    2392     3854656 :                 if (__isset) {
    2393           0 :                         if (__isset->common.fn_flags & ZEND_ACC_STATIC) {
    2394           0 :                                 zend_error(error_type, "Method %s::%s() cannot be static", ZSTR_VAL(scope->name), ZSTR_VAL(__isset->common.function_name));
    2395             :                         }
    2396           0 :                         __isset->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
    2397             :                 }
    2398     3854656 :                 if (__debugInfo) {
    2399           0 :                         if (__debugInfo->common.fn_flags & ZEND_ACC_STATIC) {
    2400           0 :                                 zend_error(error_type, "Method %s::%s() cannot be static", ZSTR_VAL(scope->name), ZSTR_VAL(__debugInfo->common.function_name));
    2401             :                         }
    2402             :                 }
    2403             : 
    2404     3854656 :                 if (ctor && ctor->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE && ctor->common.fn_flags & ZEND_ACC_CTOR) {
    2405           0 :                         zend_error_noreturn(E_CORE_ERROR, "Constructor %s::%s() cannot declare a return type", ZSTR_VAL(scope->name), ZSTR_VAL(ctor->common.function_name));
    2406             :                 }
    2407             : 
    2408     3854656 :                 if (dtor && dtor->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE && dtor->common.fn_flags & ZEND_ACC_DTOR) {
    2409           0 :                         zend_error_noreturn(E_CORE_ERROR, "Destructor %s::%s() cannot declare a return type", ZSTR_VAL(scope->name), ZSTR_VAL(dtor->common.function_name));
    2410             :                 }
    2411             : 
    2412     3854656 :                 if (clone && clone->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE && dtor->common.fn_flags & ZEND_ACC_DTOR) {
    2413           0 :                         zend_error_noreturn(E_CORE_ERROR, "%s::%s() cannot declare a return type", ZSTR_VAL(scope->name), ZSTR_VAL(clone->common.function_name));
    2414             :                 }
    2415     3854656 :                 efree((char*)lc_class_name);
    2416             :         }
    2417     5476449 :         return SUCCESS;
    2418             : }
    2419             : /* }}} */
    2420             : 
    2421             : /* count=-1 means erase all functions, otherwise,
    2422             :  * erase the first count functions
    2423             :  */
    2424     1601292 : ZEND_API void zend_unregister_functions(const zend_function_entry *functions, int count, HashTable *function_table) /* {{{ */
    2425             : {
    2426     1601292 :         const zend_function_entry *ptr = functions;
    2427     1601292 :         int i=0;
    2428     1601292 :         HashTable *target_function_table = function_table;
    2429             :         zend_string *lowercase_name;
    2430             :         size_t fname_len;
    2431             : 
    2432     1601292 :         if (!target_function_table) {
    2433     1601292 :                 target_function_table = CG(function_table);
    2434             :         }
    2435    55047767 :         while (ptr->fname) {
    2436    51845183 :                 if (count!=-1 && i>=count) {
    2437           0 :                         break;
    2438             :                 }
    2439    51845183 :                 fname_len = strlen(ptr->fname);
    2440    51845183 :                 lowercase_name = zend_string_alloc(fname_len, 0);
    2441    51845183 :                 zend_str_tolower_copy(ZSTR_VAL(lowercase_name), ptr->fname, fname_len);
    2442    51845183 :                 zend_hash_del(target_function_table, lowercase_name);
    2443             :                 zend_string_free(lowercase_name);
    2444    51845183 :                 ptr++;
    2445    51845183 :                 i++;
    2446             :         }
    2447     1601292 : }
    2448             : /* }}} */
    2449             : 
    2450       23328 : ZEND_API int zend_startup_module(zend_module_entry *module) /* {{{ */
    2451             : {
    2452       23328 :         if ((module = zend_register_internal_module(module)) != NULL && zend_startup_module_ex(module) == SUCCESS) {
    2453       23328 :                 return SUCCESS;
    2454             :         }
    2455           0 :         return FAILURE;
    2456             : }
    2457             : /* }}} */
    2458             : 
    2459           0 : ZEND_API int zend_get_module_started(const char *module_name) /* {{{ */
    2460             : {
    2461             :         zend_module_entry *module;
    2462             : 
    2463           0 :         module = zend_hash_str_find_ptr(&module_registry, module_name, strlen(module_name));
    2464           0 :         return (module && module->module_started) ? SUCCESS : FAILURE;
    2465             : }
    2466             : /* }}} */
    2467             : 
    2468           0 : static int clean_module_class(zval *el, void *arg) /* {{{ */
    2469             : {
    2470           0 :         zend_class_entry *ce = (zend_class_entry *)Z_PTR_P(el);
    2471           0 :         int module_number = *(int *)arg;
    2472           0 :         if (ce->type == ZEND_INTERNAL_CLASS && ce->info.internal.module->module_number == module_number) {
    2473           0 :                 return ZEND_HASH_APPLY_REMOVE;
    2474             :         } else {
    2475           0 :                 return ZEND_HASH_APPLY_KEEP;
    2476             :         }
    2477             : }
    2478             : /* }}} */
    2479             : 
    2480           0 : static void clean_module_classes(int module_number) /* {{{ */
    2481             : {
    2482           0 :         zend_hash_apply_with_argument(EG(class_table), clean_module_class, (void *) &module_number);
    2483           0 : }
    2484             : /* }}} */
    2485             : 
    2486     1648380 : void module_destructor(zend_module_entry *module) /* {{{ */
    2487             : {
    2488             : 
    2489     1648380 :         if (module->type == MODULE_TEMPORARY) {
    2490           0 :                 zend_clean_module_rsrc_dtors(module->module_number);
    2491           0 :                 clean_module_constants(module->module_number);
    2492           0 :                 clean_module_classes(module->module_number);
    2493             :         }
    2494             : 
    2495     1648380 :         if (module->module_started && module->module_shutdown_func) {
    2496             : #if 0
    2497             :                 zend_printf("%s: Module shutdown\n", module->name);
    2498             : #endif
    2499     1130412 :                 module->module_shutdown_func(module->type, module->module_number);
    2500             :         }
    2501             : 
    2502             :         /* Deinitilaise module globals */
    2503     1648380 :         if (module->globals_size) {
    2504             : #ifdef ZTS
    2505             :                 if (*module->globals_id_ptr) {
    2506             :                         ts_free_id(*module->globals_id_ptr);
    2507             :                 }
    2508             : #else
    2509      800496 :                 if (module->globals_dtor) {
    2510      164808 :                         module->globals_dtor(module->globals_ptr);
    2511             :                 }
    2512             : #endif
    2513             :         }
    2514             : 
    2515     1648380 :         module->module_started=0;
    2516     1648380 :         if (module->functions) {
    2517     1601292 :                 zend_unregister_functions(module->functions, -1, NULL);
    2518             :         }
    2519             : 
    2520             : #if HAVE_LIBDL
    2521             : #if !(defined(NETWARE) && defined(APACHE_1_BUILD))
    2522     1648380 :         if (module->handle && !getenv("ZEND_DONT_UNLOAD_MODULES")) {
    2523           0 :                 DL_UNLOAD(module->handle);
    2524             :         }
    2525             : #endif
    2526             : #endif
    2527     1648380 : }
    2528             : /* }}} */
    2529             : 
    2530       23458 : ZEND_API void zend_activate_modules(void) /* {{{ */
    2531             : {
    2532       23458 :         zend_module_entry **p = module_request_startup_handlers;
    2533             : 
    2534      445765 :         while (*p) {
    2535      398849 :                 zend_module_entry *module = *p;
    2536             : 
    2537      398849 :                 if (module->request_startup_func(module->type, module->module_number)==FAILURE) {
    2538           0 :                         zend_error(E_WARNING, "request_startup() for %s module failed", module->name);
    2539           0 :                         exit(1);
    2540             :                 }
    2541      398849 :                 p++;
    2542             :         }
    2543       23458 : }
    2544             : /* }}} */
    2545             : 
    2546             : /* call request shutdown for all modules */
    2547           0 : static int module_registry_cleanup(zval *zv) /* {{{ */
    2548             : {
    2549           0 :         zend_module_entry *module = Z_PTR_P(zv);
    2550             : 
    2551           0 :         if (module->request_shutdown_func) {
    2552             : #if 0
    2553             :                 zend_printf("%s: Request shutdown\n", module->name);
    2554             : #endif
    2555           0 :                 module->request_shutdown_func(module->type, module->module_number);
    2556             :         }
    2557           0 :         return 0;
    2558             : }
    2559             : /* }}} */
    2560             : 
    2561       23500 : ZEND_API void zend_deactivate_modules(void) /* {{{ */
    2562             : {
    2563       23500 :         EG(current_execute_data) = NULL; /* we're no longer executing anything */
    2564             : 
    2565       23500 :         zend_try {
    2566       23500 :                 if (EG(full_tables_cleanup)) {
    2567           0 :                         zend_hash_reverse_apply(&module_registry, module_registry_cleanup);
    2568             :                 } else {
    2569       23500 :                         zend_module_entry **p = module_request_shutdown_handlers;
    2570             : 
    2571      540563 :                         while (*p) {
    2572      493563 :                                 zend_module_entry *module = *p;
    2573             : 
    2574      493563 :                                 module->request_shutdown_func(module->type, module->module_number);
    2575      493563 :                                 p++;
    2576             :                         }
    2577             :                 }
    2578       23500 :         } zend_end_try();
    2579       23500 : }
    2580             : /* }}} */
    2581             : 
    2582       23498 : ZEND_API void zend_cleanup_internal_classes(void) /* {{{ */
    2583             : {
    2584       23498 :         zend_class_entry **p = class_cleanup_handlers;
    2585             : 
    2586       46996 :         while (*p) {
    2587           0 :                 zend_cleanup_internal_class_data(*p);
    2588           0 :                 p++;
    2589             :         }
    2590       23498 : }
    2591             : /* }}} */
    2592             : 
    2593           0 : int module_registry_unload_temp(const zend_module_entry *module) /* {{{ */
    2594             : {
    2595           0 :         return (module->type == MODULE_TEMPORARY) ? ZEND_HASH_APPLY_REMOVE : ZEND_HASH_APPLY_STOP;
    2596             : }
    2597             : /* }}} */
    2598             : 
    2599           0 : static int module_registry_unload_temp_wrapper(zval *el) /* {{{ */
    2600             : {
    2601           0 :         zend_module_entry *module = (zend_module_entry *)Z_PTR_P(el);
    2602           0 :         return module_registry_unload_temp((const zend_module_entry *)module);
    2603             : }
    2604             : /* }}} */
    2605             : 
    2606           0 : static int exec_done_cb(zval *el) /* {{{ */
    2607             : {
    2608           0 :         zend_module_entry *module = (zend_module_entry *)Z_PTR_P(el);
    2609           0 :         if (module->post_deactivate_func) {
    2610           0 :                 module->post_deactivate_func();
    2611             :         }
    2612           0 :         return 0;
    2613             : }
    2614             : /* }}} */
    2615             : 
    2616       23500 : ZEND_API void zend_post_deactivate_modules(void) /* {{{ */
    2617             : {
    2618       23500 :         if (EG(full_tables_cleanup)) {
    2619           0 :                 zend_hash_apply(&module_registry, exec_done_cb);
    2620           0 :                 zend_hash_reverse_apply(&module_registry, module_registry_unload_temp_wrapper);
    2621             :         } else {
    2622       23500 :                 zend_module_entry **p = module_post_deactivate_handlers;
    2623             : 
    2624       93871 :                 while (*p) {
    2625       46871 :                         zend_module_entry *module = *p;
    2626             : 
    2627       46871 :                         module->post_deactivate_func();
    2628       46871 :                         p++;
    2629             :                 }
    2630             :         }
    2631       23500 : }
    2632             : /* }}} */
    2633             : 
    2634             : /* return the next free module number */
    2635     1622076 : ZEND_API int zend_next_free_module(void) /* {{{ */
    2636             : {
    2637     1622076 :         return zend_hash_num_elements(&module_registry) + 1;
    2638             : }
    2639             : /* }}} */
    2640             : 
    2641     4536272 : static zend_class_entry *do_register_internal_class(zend_class_entry *orig_class_entry, uint32_t ce_flags) /* {{{ */
    2642             : {
    2643     4536272 :         zend_class_entry *class_entry = malloc(sizeof(zend_class_entry));
    2644     9072544 :         zend_string *lowercase_name = zend_string_alloc(ZSTR_LEN(orig_class_entry->name), 1);
    2645     4536272 :         *class_entry = *orig_class_entry;
    2646             : 
    2647     4536272 :         class_entry->type = ZEND_INTERNAL_CLASS;
    2648     4536272 :         zend_initialize_class_data(class_entry, 0);
    2649     4536272 :         class_entry->ce_flags = ce_flags | ZEND_ACC_CONSTANTS_UPDATED;
    2650     4536272 :         class_entry->info.internal.module = EG(current_module);
    2651             : 
    2652     4536272 :         if (class_entry->info.internal.builtin_functions) {
    2653     3854656 :                 zend_register_functions(class_entry, class_entry->info.internal.builtin_functions, &class_entry->function_table, MODULE_PERSISTENT);
    2654             :         }
    2655             : 
    2656     4536272 :         zend_str_tolower_copy(ZSTR_VAL(lowercase_name), ZSTR_VAL(orig_class_entry->name), ZSTR_LEN(class_entry->name));
    2657     4536272 :         lowercase_name = zend_new_interned_string(lowercase_name);
    2658     4536272 :         zend_hash_update_ptr(CG(class_table), lowercase_name, class_entry);
    2659             :         zend_string_release(lowercase_name);
    2660     4536272 :         return class_entry;
    2661             : }
    2662             : /* }}} */
    2663             : 
    2664             : /* If parent_ce is not NULL then it inherits from parent_ce
    2665             :  * If parent_ce is NULL and parent_name isn't then it looks for the parent and inherits from it
    2666             :  * If both parent_ce and parent_name are NULL it does a regular class registration
    2667             :  * If parent_name is specified but not found NULL is returned
    2668             :  */
    2669     2444416 : ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce) /* {{{ */
    2670             : {
    2671             :         zend_class_entry *register_class;
    2672             : 
    2673     2444416 :         register_class = zend_register_internal_class(class_entry);
    2674             : 
    2675     2444416 :         if (parent_ce) {
    2676     1809808 :                 zend_do_inheritance(register_class, parent_ce);
    2677             :         }
    2678     2444416 :         return register_class;
    2679             : }
    2680             : /* }}} */
    2681             : 
    2682     1762800 : ZEND_API void zend_class_implements(zend_class_entry *class_entry, int num_interfaces, ...) /* {{{ */
    2683             : {
    2684             :         zend_class_entry *interface_entry;
    2685             :         va_list interface_list;
    2686     1762800 :         va_start(interface_list, num_interfaces);
    2687             : 
    2688     5335408 :         while (num_interfaces--) {
    2689     1809808 :                 interface_entry = va_arg(interface_list, zend_class_entry *);
    2690     1809808 :                 zend_do_implement_interface(class_entry, interface_entry);
    2691             :         }
    2692             : 
    2693     1762800 :         va_end(interface_list);
    2694     1762800 : }
    2695             : /* }}} */
    2696             : 
    2697             : /* A class that contains at least one abstract method automatically becomes an abstract class.
    2698             :  */
    2699     4183712 : ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *orig_class_entry) /* {{{ */
    2700             : {
    2701     4183712 :         return do_register_internal_class(orig_class_entry, 0);
    2702             : }
    2703             : /* }}} */
    2704             : 
    2705      352560 : ZEND_API zend_class_entry *zend_register_internal_interface(zend_class_entry *orig_class_entry) /* {{{ */
    2706             : {
    2707      352560 :         return do_register_internal_class(orig_class_entry, ZEND_ACC_INTERFACE);
    2708             : }
    2709             : /* }}} */
    2710             : 
    2711          31 : ZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zend_class_entry *ce) /* {{{ */
    2712             : {
    2713             :         zend_string *lcname;
    2714             : 
    2715          31 :         if (name[0] == '\\') {
    2716           0 :                 lcname = zend_string_alloc(name_len-1, 1);
    2717           0 :                 zend_str_tolower_copy(ZSTR_VAL(lcname), name+1, name_len-1);
    2718             :         } else {
    2719          31 :                 lcname = zend_string_alloc(name_len, 1);
    2720          31 :                 zend_str_tolower_copy(ZSTR_VAL(lcname), name, name_len);
    2721             :         }
    2722             : 
    2723          31 :         zend_assert_valid_class_name(lcname);
    2724             : 
    2725          54 :         ce = zend_hash_add_ptr(CG(class_table), lcname, ce);
    2726             :         zend_string_release(lcname);
    2727          27 :         if (ce) {
    2728          23 :                 ce->refcount++;
    2729          23 :                 return SUCCESS;
    2730             :         }
    2731           4 :         return FAILURE;
    2732             : }
    2733             : /* }}} */
    2734             : 
    2735           0 : ZEND_API int zend_set_hash_symbol(zval *symbol, const char *name, int name_length, zend_bool is_ref, int num_symbol_tables, ...) /* {{{ */
    2736             : {
    2737             :         HashTable *symbol_table;
    2738             :         va_list symbol_table_list;
    2739             : 
    2740           0 :         if (num_symbol_tables <= 0) return FAILURE;
    2741             : 
    2742           0 :         if (is_ref) {
    2743           0 :                 ZVAL_MAKE_REF(symbol);
    2744             :         }
    2745             : 
    2746           0 :         va_start(symbol_table_list, num_symbol_tables);
    2747           0 :         while (num_symbol_tables-- > 0) {
    2748           0 :                 symbol_table = va_arg(symbol_table_list, HashTable *);
    2749           0 :                 zend_hash_str_update(symbol_table, name, name_length, symbol);
    2750           0 :                 if (Z_REFCOUNTED_P(symbol)) {
    2751             :                         Z_ADDREF_P(symbol);
    2752             :                 }
    2753             :         }
    2754           0 :         va_end(symbol_table_list);
    2755           0 :         return SUCCESS;
    2756             : }
    2757             : /* }}} */
    2758             : 
    2759             : /* Disabled functions support */
    2760             : 
    2761             : /* {{{ proto void display_disabled_function(void)
    2762             : Dummy function which displays an error when a disabled function is called. */
    2763           6 : ZEND_API ZEND_FUNCTION(display_disabled_function)
    2764             : {
    2765           6 :         zend_error(E_WARNING, "%s() has been disabled for security reasons", get_active_function_name());
    2766           6 : }
    2767             : /* }}} */
    2768             : 
    2769           8 : ZEND_API int zend_disable_function(char *function_name, size_t function_name_length) /* {{{ */
    2770             : {
    2771             :         zend_internal_function *func;
    2772          16 :         if ((func = zend_hash_str_find_ptr(CG(function_table), function_name, function_name_length))) {
    2773           8 :             func->fn_flags &= ~(ZEND_ACC_VARIADIC | ZEND_ACC_HAS_TYPE_HINTS);
    2774           8 :                 func->num_args = 0;
    2775           8 :                 func->arg_info = NULL;
    2776           8 :                 func->handler = ZEND_FN(display_disabled_function);
    2777           8 :                 return SUCCESS;
    2778             :         }
    2779           0 :         return FAILURE;
    2780             : }
    2781             : /* }}} */
    2782             : 
    2783             : #ifdef ZEND_WIN32
    2784             : #pragma optimize("", off)
    2785             : #endif
    2786           1 : static zend_object *display_disabled_class(zend_class_entry *class_type) /* {{{ */
    2787             : {
    2788             :         zend_object *intern;
    2789             : 
    2790           1 :         intern = zend_objects_new(class_type);
    2791           1 :         zend_error(E_WARNING, "%s() has been disabled for security reasons", ZSTR_VAL(class_type->name));
    2792           1 :         return intern;
    2793             : }
    2794             : #ifdef ZEND_WIN32
    2795             : #pragma optimize("", on)
    2796             : #endif
    2797             : /* }}} */
    2798             : 
    2799             : static const zend_function_entry disabled_class_new[] = {
    2800             :         ZEND_FE_END
    2801             : };
    2802             : 
    2803           1 : ZEND_API int zend_disable_class(char *class_name, size_t class_name_length) /* {{{ */
    2804             : {
    2805             :         zend_class_entry *disabled_class;
    2806             :         zend_string *key;
    2807             : 
    2808           1 :         key = zend_string_alloc(class_name_length, 0);
    2809           1 :         zend_str_tolower_copy(ZSTR_VAL(key), class_name, class_name_length);
    2810           2 :         disabled_class = zend_hash_find_ptr(CG(class_table), key);
    2811           1 :         if (!disabled_class) {
    2812           0 :                 return FAILURE;
    2813             :         }
    2814           1 :         INIT_CLASS_ENTRY_INIT_METHODS((*disabled_class), disabled_class_new, NULL, NULL, NULL, NULL, NULL);
    2815           1 :         disabled_class->create_object = display_disabled_class;
    2816           1 :         zend_hash_clean(&disabled_class->function_table);
    2817           1 :         return SUCCESS;
    2818             : }
    2819             : /* }}} */
    2820             : 
    2821         390 : static int zend_is_callable_check_class(zend_string *name, zend_class_entry *scope, zend_fcall_info_cache *fcc, int *strict_class, char **error) /* {{{ */
    2822             : {
    2823         390 :         int ret = 0;
    2824             :         zend_class_entry *ce;
    2825         390 :         size_t name_len = ZSTR_LEN(name);
    2826             :         zend_string *lcname;
    2827             :         ALLOCA_FLAG(use_heap);
    2828             : 
    2829         780 :         ZSTR_ALLOCA_ALLOC(lcname, name_len, use_heap);
    2830         390 :         zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(name), name_len);
    2831             : 
    2832         390 :         *strict_class = 0;
    2833         412 :         if (zend_string_equals_literal(lcname, "self")) {
    2834          22 :                 if (!scope) {
    2835           3 :                         if (error) *error = estrdup("cannot access self:: when no class scope is active");
    2836             :                 } else {
    2837          19 :                         fcc->called_scope = zend_get_called_scope(EG(current_execute_data));
    2838          19 :                         fcc->calling_scope = scope;
    2839          19 :                         if (!fcc->object) {
    2840          16 :                                 fcc->object = zend_get_this_object(EG(current_execute_data));
    2841             :                         }
    2842          19 :                         ret = 1;
    2843             :                 }
    2844         405 :         } else if (zend_string_equals_literal(lcname, "parent")) {
    2845          37 :                 if (!scope) {
    2846           0 :                         if (error) *error = estrdup("cannot access parent:: when no class scope is active");
    2847          37 :                 } else if (!scope->parent) {
    2848           0 :                         if (error) *error = estrdup("cannot access parent:: when current class scope has no parent");
    2849             :                 } else {
    2850          37 :                         fcc->called_scope = zend_get_called_scope(EG(current_execute_data));
    2851          37 :                         fcc->calling_scope = scope->parent;
    2852          37 :                         if (!fcc->object) {
    2853          19 :                                 fcc->object = zend_get_this_object(EG(current_execute_data));
    2854             :                         }
    2855          37 :                         *strict_class = 1;
    2856          37 :                         ret = 1;
    2857             :                 }
    2858         343 :         } else if (zend_string_equals_literal(lcname, "static")) {
    2859          12 :                 zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data));
    2860             : 
    2861          12 :                 if (!called_scope) {
    2862           0 :                         if (error) *error = estrdup("cannot access static:: when no class scope is active");
    2863             :                 } else {
    2864          12 :                         fcc->called_scope = called_scope;
    2865          12 :                         fcc->calling_scope = called_scope;
    2866          12 :                         if (!fcc->object) {
    2867          11 :                                 fcc->object = zend_get_this_object(EG(current_execute_data));
    2868             :                         }
    2869          12 :                         *strict_class = 1;
    2870          12 :                         ret = 1;
    2871             :                 }
    2872         319 :         } else if ((ce = zend_lookup_class_ex(name, NULL, 1)) != NULL) {
    2873             :                 zend_class_entry *scope;
    2874         305 :                 zend_execute_data *ex = EG(current_execute_data);
    2875             : 
    2876         840 :                 while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
    2877         230 :                         ex = ex->prev_execute_data;
    2878             :                 }
    2879         305 :                 scope = ex ? ex->func->common.scope : NULL;
    2880         305 :                 fcc->calling_scope = ce;
    2881         352 :                 if (scope && !fcc->object) {
    2882          47 :                         zend_object *object = zend_get_this_object(EG(current_execute_data));
    2883             : 
    2884         141 :                         if (object &&
    2885          33 :                             instanceof_function(object->ce, scope) &&
    2886          33 :                             instanceof_function(scope, fcc->calling_scope)) {
    2887          28 :                                 fcc->object = object;
    2888          28 :                                 fcc->called_scope = object->ce;
    2889             :                         } else {
    2890          19 :                                 fcc->called_scope = fcc->calling_scope;
    2891             :                         }
    2892             :                 } else {
    2893         258 :                         fcc->called_scope = fcc->object ? fcc->object->ce : fcc->calling_scope;
    2894             :                 }
    2895         305 :                 *strict_class = 1;
    2896         305 :                 ret = 1;
    2897             :         } else {
    2898          13 :                 if (error) zend_spprintf(error, 0, "class '%.*s' not found", (int)name_len, ZSTR_VAL(name));
    2899             :         }
    2900         389 :         ZSTR_ALLOCA_FREE(lcname, use_heap);
    2901         389 :         return ret;
    2902             : }
    2903             : /* }}} */
    2904             : 
    2905       16080 : static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fcall_info_cache *fcc, int strict_class, char **error) /* {{{ */
    2906             : {
    2907       16080 :         zend_class_entry *ce_org = fcc->calling_scope;
    2908       16080 :         int retval = 0;
    2909             :         zend_string *mname, *cname;
    2910             :         zend_string *lmname;
    2911             :         const char *colon;
    2912             :         size_t clen, mlen;
    2913             :         HashTable *ftable;
    2914       16080 :         int call_via_handler = 0;
    2915             :         zend_class_entry *scope;
    2916             :         ALLOCA_FLAG(use_heap)
    2917             : 
    2918       16080 :         if (error) {
    2919       14907 :                 *error = NULL;
    2920             :         }
    2921             : 
    2922       16080 :         fcc->calling_scope = NULL;
    2923       16080 :         fcc->function_handler = NULL;
    2924             : 
    2925       16080 :         if (!ce_org) {
    2926             :                 zend_string *lmname;
    2927             : 
    2928             :                 /* Skip leading \ */
    2929        5955 :                 if (UNEXPECTED(Z_STRVAL_P(callable)[0] == '\\')) {
    2930          38 :                         ZSTR_ALLOCA_INIT(lmname, Z_STRVAL_P(callable) + 1, Z_STRLEN_P(callable) - 1, use_heap);
    2931             :                 } else {
    2932        5936 :                         lmname = Z_STR_P(callable);
    2933             :                 }
    2934             :                 /* Check if function with given name exists.
    2935             :                  * This may be a compound name that includes namespace name */
    2936       11910 :                 if (EXPECTED((fcc->function_handler = zend_hash_find_ptr(EG(function_table), lmname)) != NULL)) {
    2937        5416 :                         if (lmname != Z_STR_P(callable)) {
    2938           2 :                                 ZSTR_ALLOCA_FREE(lmname, use_heap);
    2939             :                         }
    2940        5416 :                         fcc->initialized = 1;
    2941        5416 :                         return 1;
    2942             :                 } else {
    2943         539 :                         if (lmname == Z_STR_P(callable)) {
    2944        1044 :                                 ZSTR_ALLOCA_INIT(lmname, Z_STRVAL_P(callable), Z_STRLEN_P(callable), use_heap);
    2945             :                         } else {
    2946             :                                 zend_string_forget_hash_val(lmname);
    2947             :                         }
    2948         539 :                         zend_str_tolower(ZSTR_VAL(lmname), ZSTR_LEN(lmname));
    2949        1078 :                         if ((fcc->function_handler = zend_hash_find_ptr(EG(function_table), lmname)) != NULL) {
    2950         197 :                                 ZSTR_ALLOCA_FREE(lmname, use_heap);
    2951         197 :                                 fcc->initialized = 1;
    2952         197 :                                 return 1;
    2953             :                         }
    2954             :                 }
    2955         342 :                 if (lmname != Z_STR_P(callable)) {
    2956         342 :                         ZSTR_ALLOCA_FREE(lmname, use_heap);
    2957             :                 }
    2958             :         }
    2959             : 
    2960             :         /* Split name into class/namespace and method/function names */
    2961       21373 :         if ((colon = zend_memrchr(Z_STRVAL_P(callable), ':', Z_STRLEN_P(callable))) != NULL &&
    2962         148 :                 colon > Z_STRVAL_P(callable) &&
    2963         148 :                 *(colon-1) == ':'
    2964             :         ) {
    2965         148 :                 colon--;
    2966         148 :                 clen = colon - Z_STRVAL_P(callable);
    2967         148 :                 mlen = Z_STRLEN_P(callable) - clen - 2;
    2968             : 
    2969         148 :                 if (colon == Z_STRVAL_P(callable)) {
    2970           0 :                         if (error) zend_spprintf(error, 0, "invalid function name");
    2971           0 :                         return 0;
    2972             :                 }
    2973             : 
    2974             :                 /* This is a compound name.
    2975             :                  * Try to fetch class and then find static method. */
    2976         148 :                 if (ce_org) {
    2977          29 :                         scope = ce_org;
    2978             :                 } else {
    2979         119 :                         scope = zend_get_executed_scope();
    2980             :                 }
    2981             : 
    2982         296 :                 cname = zend_string_init(Z_STRVAL_P(callable), clen, 0);
    2983         148 :                 if (!zend_is_callable_check_class(cname, scope, fcc, &strict_class, error)) {
    2984             :                         zend_string_release(cname);
    2985           3 :                         return 0;
    2986             :                 }
    2987             :                 zend_string_release(cname);
    2988             : 
    2989         144 :                 ftable = &fcc->calling_scope->function_table;
    2990         144 :                 if (ce_org && !instanceof_function(ce_org, fcc->calling_scope)) {
    2991           1 :                         if (error) zend_spprintf(error, 0, "class '%s' is not a subclass of '%s'", ZSTR_VAL(ce_org->name), ZSTR_VAL(fcc->calling_scope->name));
    2992           1 :                         return 0;
    2993             :                 }
    2994         286 :                 mname = zend_string_init(Z_STRVAL_P(callable) + clen + 2, mlen, 0);
    2995       10319 :         } else if (ce_org) {
    2996             :                 /* Try to fetch find static method of given class. */
    2997       10096 :                 mlen = Z_STRLEN_P(callable);
    2998       10096 :                 mname = Z_STR_P(callable);
    2999             :                 zend_string_addref(mname);
    3000       10096 :                 ftable = &ce_org->function_table;
    3001       10096 :                 fcc->calling_scope = ce_org;
    3002             :         } else {
    3003             :                 /* We already checked for plain function before. */
    3004         223 :                 if (error && !(check_flags & IS_CALLABLE_CHECK_SILENT)) {
    3005         196 :                         zend_spprintf(error, 0, "function '%s' not found or invalid function name", Z_STRVAL_P(callable));
    3006             :                 }
    3007         223 :                 return 0;
    3008             :         }
    3009             : 
    3010       10239 :         lmname = zend_string_tolower(mname);
    3011       10961 :         if (strict_class &&
    3012         349 :             fcc->calling_scope &&
    3013         364 :                 zend_string_equals_literal(lmname, ZEND_CONSTRUCTOR_FUNC_NAME)) {
    3014           9 :                 fcc->function_handler = fcc->calling_scope->constructor;
    3015           9 :                 if (fcc->function_handler) {
    3016           9 :                         retval = 1;
    3017             :                 }
    3018       10230 :         } else if ((fcc->function_handler = zend_hash_find_ptr(ftable, lmname)) != NULL) {
    3019        9960 :                 retval = 1;
    3020        9962 :                 if ((fcc->function_handler->op_array.fn_flags & ZEND_ACC_CHANGED) &&
    3021           2 :                     !strict_class) {
    3022           1 :                         scope = zend_get_executed_scope();
    3023           2 :                         if (scope &&
    3024           1 :                             instanceof_function(fcc->function_handler->common.scope, scope)) {
    3025             :                                 zend_function *priv_fbc;
    3026             : 
    3027           4 :                                 if ((priv_fbc = zend_hash_find_ptr(&scope->function_table, lmname)) != NULL
    3028             :                                         && priv_fbc->common.fn_flags & ZEND_ACC_PRIVATE
    3029           2 :                                         && priv_fbc->common.scope == scope) {
    3030           1 :                                         fcc->function_handler = priv_fbc;
    3031             :                                 }
    3032             :                         }
    3033             :                 }
    3034       49382 :                 if ((check_flags & IS_CALLABLE_CHECK_NO_ACCESS) == 0 &&
    3035        9957 :                     (fcc->calling_scope &&
    3036       19643 :                      ((fcc->object && fcc->calling_scope->__call) ||
    3037        9822 :                       (!fcc->object && fcc->calling_scope->__callstatic)))) {
    3038         414 :                         if (fcc->function_handler->op_array.fn_flags & ZEND_ACC_PRIVATE) {
    3039           2 :                                 scope = zend_get_executed_scope();
    3040           2 :                                 if (!zend_check_private(fcc->function_handler, fcc->object ? fcc->object->ce : scope, lmname)) {
    3041           1 :                                         retval = 0;
    3042           1 :                                         fcc->function_handler = NULL;
    3043           1 :                                         goto get_function_via_handler;
    3044             :                                 }
    3045         412 :                         } else if (fcc->function_handler->common.fn_flags & ZEND_ACC_PROTECTED) {
    3046           2 :                                 scope = zend_get_executed_scope();
    3047           2 :                                 if (!zend_check_protected(fcc->function_handler->common.scope, scope)) {
    3048           1 :                                         retval = 0;
    3049           1 :                                         fcc->function_handler = NULL;
    3050           1 :                                         goto get_function_via_handler;
    3051             :                                 }
    3052             :                         }
    3053             :                 }
    3054             :         } else {
    3055             : get_function_via_handler:
    3056         512 :                 if (fcc->object && fcc->calling_scope == ce_org) {
    3057         243 :                         if (strict_class && ce_org->__call) {
    3058           3 :                                 fcc->function_handler = zend_get_call_trampoline_func(ce_org, mname, 0);
    3059           3 :                                 call_via_handler = 1;
    3060           3 :                                 retval = 1;
    3061         237 :                         } else if (fcc->object->handlers->get_method) {
    3062         237 :                                 fcc->function_handler = fcc->object->handlers->get_method(&fcc->object, mname, NULL);
    3063         237 :                                 if (fcc->function_handler) {
    3064          31 :                                         if (strict_class &&
    3065           0 :                                             (!fcc->function_handler->common.scope ||
    3066           0 :                                              !instanceof_function(ce_org, fcc->function_handler->common.scope))) {
    3067           0 :                                                 if (fcc->function_handler->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
    3068           0 :                                                         if (fcc->function_handler->type != ZEND_OVERLOADED_FUNCTION) {
    3069           0 :                                                                 zend_string_release(fcc->function_handler->common.function_name);
    3070             :                                                         }
    3071           0 :                                                         zend_free_trampoline(fcc->function_handler);
    3072             :                                                 }
    3073             :                                         } else {
    3074          31 :                                                 retval = 1;
    3075          31 :                                                 call_via_handler = (fcc->function_handler->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) != 0;
    3076             :                                         }
    3077             :                                 }
    3078             :                         }
    3079          32 :                 } else if (fcc->calling_scope) {
    3080          32 :                         if (fcc->calling_scope->get_static_method) {
    3081           0 :                                 fcc->function_handler = fcc->calling_scope->get_static_method(fcc->calling_scope, mname);
    3082             :                         } else {
    3083          32 :                                 fcc->function_handler = zend_std_get_static_method(fcc->calling_scope, mname, NULL);
    3084             :                         }
    3085          32 :                         if (fcc->function_handler) {
    3086          16 :                                 retval = 1;
    3087          16 :                                 call_via_handler = (fcc->function_handler->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) != 0;
    3088          16 :                                 if (call_via_handler && !fcc->object) {
    3089          11 :                                         zend_object *object = zend_get_this_object(EG(current_execute_data));
    3090          13 :                                         if (object &&
    3091           2 :                                             instanceof_function(object->ce, fcc->calling_scope)) {
    3092           2 :                                                 fcc->object = object;
    3093             :                                         }
    3094             :                                 }
    3095             :                         }
    3096             :                 }
    3097             :         }
    3098             : 
    3099       10239 :         if (retval) {
    3100       10017 :                 if (fcc->calling_scope && !call_via_handler) {
    3101        9967 :                         if (fcc->function_handler->common.fn_flags & ZEND_ACC_ABSTRACT) {
    3102           7 :                                 if (error) {
    3103           6 :                                         zend_spprintf(error, 0, "cannot call abstract method %s::%s()", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(fcc->function_handler->common.function_name));
    3104           6 :                                         retval = 0;
    3105             :                                 } else {
    3106           1 :                                         zend_throw_error(NULL, "Cannot call abstract method %s::%s()", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(fcc->function_handler->common.function_name));
    3107           1 :                                         retval = 0;
    3108             :                                 }
    3109        9960 :                         } else if (!fcc->object && !(fcc->function_handler->common.fn_flags & ZEND_ACC_STATIC)) {
    3110             :                                 int severity;
    3111             :                                 char *verb;
    3112          55 :                                 if (fcc->function_handler->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
    3113          52 :                                         severity = E_DEPRECATED;
    3114          52 :                                         verb = "should not";
    3115             :                                 } else {
    3116             :                                         /* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */
    3117           3 :                                         severity = E_ERROR;
    3118           3 :                                         verb = "cannot";
    3119             :                                 }
    3120          55 :                                 if ((check_flags & IS_CALLABLE_CHECK_IS_STATIC) != 0) {
    3121           5 :                                         retval = 0;
    3122             :                                 }
    3123          55 :                                 if (error) {
    3124          50 :                                         zend_spprintf(error, 0, "non-static method %s::%s() %s be called statically", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(fcc->function_handler->common.function_name), verb);
    3125          50 :                                         if (severity != E_DEPRECATED) {
    3126           1 :                                                 retval = 0;
    3127             :                                         }
    3128           5 :                                 } else if (retval) {
    3129           5 :                                         if (severity == E_ERROR) {
    3130           2 :                                                 zend_throw_error(NULL, "Non-static method %s::%s() %s be called statically", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(fcc->function_handler->common.function_name), verb);
    3131             :                                         } else {
    3132           3 :                                                 zend_error(severity, "Non-static method %s::%s() %s be called statically", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(fcc->function_handler->common.function_name), verb);
    3133             :                                         }
    3134             :                                 }
    3135             :                         }
    3136        9966 :                         if (retval && (check_flags & IS_CALLABLE_CHECK_NO_ACCESS) == 0) {
    3137        9950 :                                 if (fcc->function_handler->op_array.fn_flags & ZEND_ACC_PRIVATE) {
    3138          45 :                                         scope = zend_get_executed_scope();
    3139          45 :                                         if (!zend_check_private(fcc->function_handler, fcc->object ? fcc->object->ce : scope, lmname)) {
    3140          32 :                                                 if (error) {
    3141          32 :                                                         if (*error) {
    3142           5 :                                                                 efree(*error);
    3143             :                                                         }
    3144          32 :                                                         zend_spprintf(error, 0, "cannot access private method %s::%s()", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(fcc->function_handler->common.function_name));
    3145             :                                                 }
    3146          32 :                                                 retval = 0;
    3147             :                                         }
    3148        9905 :                                 } else if ((fcc->function_handler->common.fn_flags & ZEND_ACC_PROTECTED)) {
    3149          30 :                                         scope = zend_get_executed_scope();
    3150          30 :                                         if (!zend_check_protected(fcc->function_handler->common.scope, scope)) {
    3151          19 :                                                 if (error) {
    3152          19 :                                                         if (*error) {
    3153           1 :                                                                 efree(*error);
    3154             :                                                         }
    3155          19 :                                                         zend_spprintf(error, 0, "cannot access protected method %s::%s()", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(fcc->function_handler->common.function_name));
    3156             :                                                 }
    3157          19 :                                                 retval = 0;
    3158             :                                         }
    3159             :                                 }
    3160             :                         }
    3161             :                 }
    3162         222 :         } else if (error && !(check_flags & IS_CALLABLE_CHECK_SILENT)) {
    3163         133 :                 if (fcc->calling_scope) {
    3164         133 :                         if (error) zend_spprintf(error, 0, "class '%s' does not have a method '%s'", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(mname));
    3165             :                 } else {
    3166           0 :                         if (error) zend_spprintf(error, 0, "function '%s' does not exist", ZSTR_VAL(mname));
    3167             :                 }
    3168             :         }
    3169             :         zend_string_release(lmname);
    3170             :         zend_string_release(mname);
    3171             : 
    3172       10238 :         if (fcc->object) {
    3173        9942 :                 fcc->called_scope = fcc->object->ce;
    3174             :         }
    3175       10238 :         if (retval) {
    3176        9952 :                 fcc->initialized = 1;
    3177             :         }
    3178       10238 :         return retval;
    3179             : }
    3180             : /* }}} */
    3181             : 
    3182       18152 : ZEND_API zend_bool zend_is_callable_ex(zval *callable, zend_object *object, uint check_flags, zend_string **callable_name, zend_fcall_info_cache *fcc, char **error) /* {{{ */
    3183             : {
    3184             :         zend_bool ret;
    3185             :         zend_fcall_info_cache fcc_local;
    3186             : 
    3187       18152 :         if (callable_name) {
    3188       14619 :                 *callable_name = NULL;
    3189             :         }
    3190       18152 :         if (fcc == NULL) {
    3191        2384 :                 fcc = &fcc_local;
    3192             :         }
    3193       18152 :         if (error) {
    3194       16352 :                 *error = NULL;
    3195             :         }
    3196             : 
    3197       18152 :         fcc->initialized = 0;
    3198       18152 :         fcc->calling_scope = NULL;
    3199       18152 :         fcc->called_scope = NULL;
    3200       18152 :         fcc->function_handler = NULL;
    3201       18152 :         fcc->object = NULL;
    3202             : 
    3203       35312 :         if (object &&
    3204        8580 :             (!EG(objects_store).object_buckets ||
    3205        8580 :              !IS_OBJ_VALID(EG(objects_store).object_buckets[object->handle]))) {
    3206           0 :                 return 0;
    3207             :         }
    3208             : 
    3209             : again:
    3210       18153 :         switch (Z_TYPE_P(callable)) {
    3211             :                 case IS_STRING:
    3212       14593 :                         if (object) {
    3213        8577 :                                 fcc->object = object;
    3214        8577 :                                 fcc->calling_scope = object->ce;
    3215        8577 :                                 if (callable_name) {
    3216             :                                         char *ptr;
    3217             : 
    3218       17142 :                                         *callable_name = zend_string_alloc(ZSTR_LEN(fcc->calling_scope->name) + Z_STRLEN_P(callable) + sizeof("::") - 1, 0);
    3219        8571 :                                         ptr = ZSTR_VAL(*callable_name);
    3220        8571 :                                         memcpy(ptr, ZSTR_VAL(fcc->calling_scope->name), ZSTR_LEN(fcc->calling_scope->name));
    3221        8571 :                                         ptr += ZSTR_LEN(fcc->calling_scope->name);
    3222        8571 :                                         memcpy(ptr, "::", sizeof("::") - 1);
    3223        8571 :                                         ptr += sizeof("::") - 1;
    3224        8571 :                                         memcpy(ptr, Z_STRVAL_P(callable), Z_STRLEN_P(callable) + 1);
    3225             :                                 }
    3226        6016 :                         } else if (callable_name) {
    3227        7556 :                                 *callable_name = zend_string_copy(Z_STR_P(callable));
    3228             :                         }
    3229       14593 :                         if (check_flags & IS_CALLABLE_CHECK_SYNTAX_ONLY) {
    3230          61 :                                 fcc->called_scope = fcc->calling_scope;
    3231          61 :                                 return 1;
    3232             :                         }
    3233             : 
    3234       14532 :                         ret = zend_is_callable_check_func(check_flags, callable, fcc, 0, error);
    3235       17001 :                         if (fcc == &fcc_local &&
    3236         688 :                             fcc->function_handler &&
    3237         594 :                                 ((fcc->function_handler->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) ||
    3238         594 :                              fcc->function_handler->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY ||
    3239         594 :                              fcc->function_handler->type == ZEND_OVERLOADED_FUNCTION)) {
    3240           0 :                                 if (fcc->function_handler->type != ZEND_OVERLOADED_FUNCTION) {
    3241           0 :                                         zend_string_release(fcc->function_handler->common.function_name);
    3242             :                                 }
    3243           0 :                                 zend_free_trampoline(fcc->function_handler);
    3244             :                         }
    3245       14531 :                         return ret;
    3246             : 
    3247             :                 case IS_ARRAY:
    3248             :                         {
    3249        1892 :                                 zval *method = NULL;
    3250        1892 :                                 zval *obj = NULL;
    3251        1892 :                                 int strict_class = 0;
    3252             : 
    3253        1892 :                                 if (zend_hash_num_elements(Z_ARRVAL_P(callable)) == 2) {
    3254        1813 :                                         obj = zend_hash_index_find(Z_ARRVAL_P(callable), 0);
    3255        1813 :                                         method = zend_hash_index_find(Z_ARRVAL_P(callable), 1);
    3256             :                                 }
    3257             : 
    3258             :                                 do {
    3259        1892 :                                         if (obj == NULL || method == NULL) {
    3260             :                                                 break;
    3261             :                                         }
    3262             : 
    3263        1792 :                                         ZVAL_DEREF(method);
    3264        1792 :                                         if (Z_TYPE_P(method) != IS_STRING) {
    3265          46 :                                                 break;
    3266             :                                         }
    3267             : 
    3268        1746 :                                         ZVAL_DEREF(obj);
    3269        1746 :                                         if (Z_TYPE_P(obj) == IS_STRING) {
    3270         260 :                                                 if (callable_name) {
    3271             :                                                         char *ptr;
    3272             : 
    3273             : 
    3274         136 :                                                         *callable_name = zend_string_alloc(Z_STRLEN_P(obj) + Z_STRLEN_P(method) + sizeof("::") - 1, 0);
    3275          68 :                                                         ptr = ZSTR_VAL(*callable_name);
    3276          68 :                                                         memcpy(ptr, Z_STRVAL_P(obj), Z_STRLEN_P(obj));
    3277          68 :                                                         ptr += Z_STRLEN_P(obj);
    3278          68 :                                                         memcpy(ptr, "::", sizeof("::") - 1);
    3279          68 :                                                         ptr += sizeof("::") - 1;
    3280          68 :                                                         memcpy(ptr, Z_STRVAL_P(method), Z_STRLEN_P(method) + 1);
    3281             :                                                 }
    3282             : 
    3283         260 :                                                 if (check_flags & IS_CALLABLE_CHECK_SYNTAX_ONLY) {
    3284          18 :                                                         return 1;
    3285             :                                                 }
    3286             : 
    3287         242 :                                                 if (!zend_is_callable_check_class(Z_STR_P(obj), zend_get_executed_scope(), fcc, &strict_class, error)) {
    3288          13 :                                                         return 0;
    3289             :                                                 }
    3290             : 
    3291        1486 :                                         } else if (Z_TYPE_P(obj) == IS_OBJECT) {
    3292        2870 :                                                 if (!EG(objects_store).object_buckets ||
    3293        1435 :                                                     !IS_OBJ_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(obj)])) {
    3294           0 :                                                         return 0;
    3295             :                                                 }
    3296             : 
    3297        1435 :                                                 fcc->calling_scope = Z_OBJCE_P(obj); /* TBFixed: what if it's overloaded? */
    3298             : 
    3299        1435 :                                                 fcc->object = Z_OBJ_P(obj);
    3300             : 
    3301        1435 :                                                 if (callable_name) {
    3302             :                                                         char *ptr;
    3303             : 
    3304        2198 :                                                         *callable_name = zend_string_alloc(ZSTR_LEN(fcc->calling_scope->name) + Z_STRLEN_P(method) + sizeof("::") - 1, 0);
    3305        1099 :                                                         ptr = ZSTR_VAL(*callable_name);
    3306        1099 :                                                         memcpy(ptr, ZSTR_VAL(fcc->calling_scope->name), ZSTR_LEN(fcc->calling_scope->name));
    3307        1099 :                                                         ptr += ZSTR_LEN(fcc->calling_scope->name);
    3308        1099 :                                                         memcpy(ptr, "::", sizeof("::") - 1);
    3309        1099 :                                                         ptr += sizeof("::") - 1;
    3310        1099 :                                                         memcpy(ptr, Z_STRVAL_P(method), Z_STRLEN_P(method) + 1);
    3311             :                                                 }
    3312             : 
    3313        1435 :                                                 if (check_flags & IS_CALLABLE_CHECK_SYNTAX_ONLY) {
    3314         116 :                                                         fcc->called_scope = fcc->calling_scope;
    3315         116 :                                                         return 1;
    3316             :                                                 }
    3317             :                                         } else {
    3318          51 :                                                 break;
    3319             :                                         }
    3320             : 
    3321        1548 :                                         ret = zend_is_callable_check_func(check_flags, method, fcc, strict_class, error);
    3322        4225 :                                         if (fcc == &fcc_local &&
    3323         759 :                                             fcc->function_handler &&
    3324         641 :                                                 ((fcc->function_handler->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) ||
    3325         639 :                                              fcc->function_handler->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY ||
    3326         639 :                                              fcc->function_handler->type == ZEND_OVERLOADED_FUNCTION)) {
    3327           2 :                                                 if (fcc->function_handler->type != ZEND_OVERLOADED_FUNCTION) {
    3328           2 :                                                         zend_string_release(fcc->function_handler->common.function_name);
    3329             :                                                 }
    3330           2 :                                                 zend_free_trampoline(fcc->function_handler);
    3331             :                                         }
    3332        1547 :                                         return ret;
    3333             : 
    3334             :                                 } while (0);
    3335         197 :                                 if (zend_hash_num_elements(Z_ARRVAL_P(callable)) == 2) {
    3336         430 :                                         if (!obj || (!Z_ISREF_P(obj)?
    3337         194 :                                                                 (Z_TYPE_P(obj) != IS_STRING && Z_TYPE_P(obj) != IS_OBJECT) :
    3338           0 :                                                                 (Z_TYPE_P(Z_REFVAL_P(obj)) != IS_STRING && Z_TYPE_P(Z_REFVAL_P(obj)) != IS_OBJECT))) {
    3339         116 :                                                 if (error) zend_spprintf(error, 0, "first array member is not a valid class name or object");
    3340             :                                         } else {
    3341           2 :                                                 if (error) zend_spprintf(error, 0, "second array member is not a valid method");
    3342             :                                         }
    3343             :                                 } else {
    3344          79 :                                         if (error) zend_spprintf(error, 0, "array must have exactly two members");
    3345             :                                 }
    3346         197 :                                 if (callable_name) {
    3347          45 :                                         *callable_name = zend_string_init("Array", sizeof("Array")-1, 0);
    3348             :                                 }
    3349             :                         }
    3350         197 :                         return 0;
    3351             :                 case IS_OBJECT:
    3352        1143 :                         if (Z_OBJ_HANDLER_P(callable, get_closure) && Z_OBJ_HANDLER_P(callable, get_closure)(callable, &fcc->calling_scope, &fcc->function_handler, &fcc->object) == SUCCESS) {
    3353        1093 :                                 fcc->called_scope = fcc->calling_scope;
    3354        1093 :                                 if (callable_name) {
    3355        1012 :                                         zend_class_entry *ce = Z_OBJCE_P(callable); /* TBFixed: what if it's overloaded? */
    3356             : 
    3357        2024 :                                         *callable_name = zend_string_alloc(ZSTR_LEN(ce->name) + sizeof("::__invoke") - 1, 0);
    3358        1012 :                                         memcpy(ZSTR_VAL(*callable_name), ZSTR_VAL(ce->name), ZSTR_LEN(ce->name));
    3359        1012 :                                         memcpy(ZSTR_VAL(*callable_name) + ZSTR_LEN(ce->name), "::__invoke", sizeof("::__invoke"));
    3360             :                                 }
    3361        1093 :                                 fcc->initialized = 1;
    3362        1093 :                                 return 1;
    3363             :                         }
    3364          50 :                         if (callable_name) {
    3365           1 :                                 *callable_name = zval_get_string(callable);
    3366             :                         }
    3367          50 :                         if (error) zend_spprintf(error, 0, "no array or string given");
    3368          50 :                         return 0;
    3369             :                 case IS_REFERENCE:
    3370           1 :                         callable = Z_REFVAL_P(callable);
    3371           1 :                         goto again;
    3372             :                 default:
    3373         524 :                         if (callable_name) {
    3374          45 :                                 *callable_name = zval_get_string(callable);
    3375             :                         }
    3376         524 :                         if (error) zend_spprintf(error, 0, "no array or string given");
    3377         524 :                         return 0;
    3378             :         }
    3379             : }
    3380             : /* }}} */
    3381             : 
    3382        1736 : ZEND_API zend_bool zend_is_callable(zval *callable, uint check_flags, zend_string **callable_name) /* {{{ */
    3383             : {
    3384        1736 :         return zend_is_callable_ex(callable, NULL, check_flags, callable_name, NULL, NULL);
    3385             : }
    3386             : /* }}} */
    3387             : 
    3388          30 : ZEND_API zend_bool zend_make_callable(zval *callable, zend_string **callable_name) /* {{{ */
    3389             : {
    3390             :         zend_fcall_info_cache fcc;
    3391             : 
    3392          30 :         if (zend_is_callable_ex(callable, NULL, IS_CALLABLE_STRICT, callable_name, &fcc, NULL)) {
    3393          28 :                 if (Z_TYPE_P(callable) == IS_STRING && fcc.calling_scope) {
    3394             :                         zval_dtor(callable);
    3395           1 :                         array_init(callable);
    3396           2 :                         add_next_index_str(callable, zend_string_copy(fcc.calling_scope->name));
    3397           2 :                         add_next_index_str(callable, zend_string_copy(fcc.function_handler->common.function_name));
    3398             :                 }
    3399         112 :                 if (fcc.function_handler &&
    3400          28 :                         ((fcc.function_handler->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) ||
    3401          28 :                      fcc.function_handler->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY ||
    3402          28 :                      fcc.function_handler->type == ZEND_OVERLOADED_FUNCTION)) {
    3403           0 :                         if (fcc.function_handler->type != ZEND_OVERLOADED_FUNCTION) {
    3404           0 :                                 zend_string_release(fcc.function_handler->common.function_name);
    3405             :                         }
    3406           0 :                         zend_free_trampoline(fcc.function_handler);
    3407             :                 }
    3408          28 :                 return 1;
    3409             :         }
    3410           1 :         return 0;
    3411             : }
    3412             : /* }}} */
    3413             : 
    3414        2871 : ZEND_API int zend_fcall_info_init(zval *callable, uint check_flags, zend_fcall_info *fci, zend_fcall_info_cache *fcc, zend_string **callable_name, char **error) /* {{{ */
    3415             : {
    3416        2871 :         if (!zend_is_callable_ex(callable, NULL, check_flags, callable_name, fcc, error)) {
    3417         724 :                 return FAILURE;
    3418             :         }
    3419             : 
    3420        2147 :         fci->size = sizeof(*fci);
    3421        2147 :         fci->object = fcc->object;
    3422        2147 :         ZVAL_COPY_VALUE(&fci->function_name, callable);
    3423        2147 :         fci->retval = NULL;
    3424        2147 :         fci->param_count = 0;
    3425        2147 :         fci->params = NULL;
    3426        2147 :         fci->no_separation = 1;
    3427             : 
    3428        2147 :         return SUCCESS;
    3429             : }
    3430             : /* }}} */
    3431             : 
    3432         586 : ZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, int free_mem) /* {{{ */
    3433             : {
    3434         586 :         if (fci->params) {
    3435         200 :                 zval *p = fci->params;
    3436         200 :                 zval *end = p + fci->param_count;
    3437             : 
    3438         735 :                 while (p != end) {
    3439             :                         i_zval_ptr_dtor(p ZEND_FILE_LINE_CC);
    3440         335 :                         p++;
    3441             :                 }
    3442         200 :                 if (free_mem) {
    3443         200 :                         efree(fci->params);
    3444         200 :                         fci->params = NULL;
    3445             :                 }
    3446             :         }
    3447         586 :         fci->param_count = 0;
    3448         586 : }
    3449             : /* }}} */
    3450             : 
    3451           0 : ZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, int *param_count, zval **params) /* {{{ */
    3452             : {
    3453           0 :         *param_count = fci->param_count;
    3454           0 :         *params = fci->params;
    3455           0 :         fci->param_count = 0;
    3456           0 :         fci->params = NULL;
    3457           0 : }
    3458             : /* }}} */
    3459             : 
    3460           0 : ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, int param_count, zval *params) /* {{{ */
    3461             : {
    3462           0 :         zend_fcall_info_args_clear(fci, 1);
    3463           0 :         fci->param_count = param_count;
    3464           0 :         fci->params = params;
    3465           0 : }
    3466             : /* }}} */
    3467             : 
    3468         227 : ZEND_API int zend_fcall_info_args_ex(zend_fcall_info *fci, zend_function *func, zval *args) /* {{{ */
    3469             : {
    3470             :         zval *arg, *params;
    3471         227 :         uint32_t n = 1;
    3472             : 
    3473         227 :         zend_fcall_info_args_clear(fci, !args);
    3474             : 
    3475         227 :         if (!args) {
    3476          11 :                 return SUCCESS;
    3477             :         }
    3478             : 
    3479         216 :         if (Z_TYPE_P(args) != IS_ARRAY) {
    3480         134 :                 return FAILURE;
    3481             :         }
    3482             : 
    3483          82 :         fci->param_count = zend_hash_num_elements(Z_ARRVAL_P(args));
    3484          82 :         fci->params = params = (zval *) erealloc(fci->params, fci->param_count * sizeof(zval));
    3485             : 
    3486         272 :         ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(args), arg) {
    3487         193 :                 if (func && !Z_ISREF_P(arg) && ARG_SHOULD_BE_SENT_BY_REF(func, n)) {
    3488           6 :                         ZVAL_NEW_REF(params, arg);
    3489           6 :                         if (Z_REFCOUNTED_P(arg)) {
    3490             :                                 Z_ADDREF_P(arg);
    3491             :                         }
    3492             :                 } else {
    3493          89 :                         ZVAL_COPY(params, arg);
    3494             :                 }
    3495          95 :                 params++;
    3496          95 :                 n++;
    3497             :         } ZEND_HASH_FOREACH_END();
    3498             : 
    3499          82 :         return SUCCESS;
    3500             : }
    3501             : /* }}} */
    3502             : 
    3503          80 : ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args) /* {{{ */
    3504             : {
    3505          80 :         return zend_fcall_info_args_ex(fci, NULL, args);
    3506             : }
    3507             : /* }}} */
    3508             : 
    3509           0 : ZEND_API int zend_fcall_info_argp(zend_fcall_info *fci, int argc, zval *argv) /* {{{ */
    3510             : {
    3511             :         int i;
    3512             : 
    3513           0 :         if (argc < 0) {
    3514           0 :                 return FAILURE;
    3515             :         }
    3516             : 
    3517           0 :         zend_fcall_info_args_clear(fci, !argc);
    3518             : 
    3519           0 :         if (argc) {
    3520           0 :                 fci->param_count = argc;
    3521           0 :                 fci->params = (zval *) erealloc(fci->params, fci->param_count * sizeof(zval));
    3522             : 
    3523           0 :                 for (i = 0; i < argc; ++i) {
    3524           0 :                         ZVAL_COPY(&fci->params[i], &argv[i]);
    3525             :                 }
    3526             :         }
    3527             : 
    3528           0 :         return SUCCESS;
    3529             : }
    3530             : /* }}} */
    3531             : 
    3532         256 : ZEND_API int zend_fcall_info_argv(zend_fcall_info *fci, int argc, va_list *argv) /* {{{ */
    3533             : {
    3534             :         int i;
    3535             :         zval *arg;
    3536             : 
    3537         256 :         if (argc < 0) {
    3538           0 :                 return FAILURE;
    3539             :         }
    3540             : 
    3541         256 :         zend_fcall_info_args_clear(fci, !argc);
    3542             : 
    3543         256 :         if (argc) {
    3544         130 :                 fci->param_count = argc;
    3545         130 :                 fci->params = (zval *) erealloc(fci->params, fci->param_count * sizeof(zval));
    3546             : 
    3547         390 :                 for (i = 0; i < argc; ++i) {
    3548         260 :                         arg = va_arg(*argv, zval *);
    3549         260 :                         ZVAL_COPY(&fci->params[i], arg);
    3550             :                 }
    3551             :         }
    3552             : 
    3553         256 :         return SUCCESS;
    3554             : }
    3555             : /* }}} */
    3556             : 
    3557         256 : ZEND_API int zend_fcall_info_argn(zend_fcall_info *fci, int argc, ...) /* {{{ */
    3558             : {
    3559             :         int ret;
    3560             :         va_list argv;
    3561             : 
    3562         256 :         va_start(argv, argc);
    3563         256 :         ret = zend_fcall_info_argv(fci, argc, &argv);
    3564         256 :         va_end(argv);
    3565             : 
    3566         256 :         return ret;
    3567             : }
    3568             : /* }}} */
    3569             : 
    3570         144 : ZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *fcc, zval *retval_ptr, zval *args) /* {{{ */
    3571             : {
    3572         144 :         zval retval, *org_params = NULL;
    3573         144 :         int result, org_count = 0;
    3574             : 
    3575         144 :         fci->retval = retval_ptr ? retval_ptr : &retval;
    3576         144 :         if (args) {
    3577           0 :                 zend_fcall_info_args_save(fci, &org_count, &org_params);
    3578           0 :                 zend_fcall_info_args(fci, args);
    3579             :         }
    3580         144 :         result = zend_call_function(fci, fcc);
    3581             : 
    3582         140 :         if (!retval_ptr && Z_TYPE(retval) != IS_UNDEF) {
    3583           0 :                 zval_ptr_dtor(&retval);
    3584             :         }
    3585         140 :         if (args) {
    3586           0 :                 zend_fcall_info_args_restore(fci, org_count, org_params);
    3587             :         }
    3588         140 :         return result;
    3589             : }
    3590             : /* }}} */
    3591             : 
    3592           1 : ZEND_API const char *zend_get_module_version(const char *module_name) /* {{{ */
    3593             : {
    3594             :         zend_string *lname;
    3595           1 :         size_t name_len = strlen(module_name);
    3596             :         zend_module_entry *module;
    3597             : 
    3598           1 :         lname = zend_string_alloc(name_len, 0);
    3599           1 :         zend_str_tolower_copy(ZSTR_VAL(lname), module_name, name_len);
    3600           1 :         module = zend_hash_find_ptr(&module_registry, lname);
    3601             :         zend_string_free(lname);
    3602           1 :         return module ? module->version : NULL;
    3603             : }
    3604             : /* }}} */
    3605             : 
    3606     1930069 : ZEND_API int zend_declare_property_ex(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment) /* {{{ */
    3607             : {
    3608             :         zend_property_info *property_info, *property_info_ptr;
    3609             : 
    3610     1930069 :         if (ce->type == ZEND_INTERNAL_CLASS) {
    3611     1927328 :                 property_info = pemalloc(sizeof(zend_property_info), 1);
    3612     1927328 :                 if ((access_type & ZEND_ACC_STATIC) || Z_CONSTANT_P(property)) {
    3613           0 :                         ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
    3614             :                 }
    3615             :         } else {
    3616        2741 :                 property_info = zend_arena_alloc(&CG(arena), sizeof(zend_property_info));
    3617        2741 :                 if (Z_CONSTANT_P(property)) {
    3618          60 :                         ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
    3619             :                 }
    3620             :         }
    3621             : 
    3622     1930069 :         if (!(access_type & ZEND_ACC_PPP_MASK)) {
    3623       47156 :                 access_type |= ZEND_ACC_PUBLIC;
    3624             :         }
    3625     1930069 :         if (access_type & ZEND_ACC_STATIC) {
    3626        1002 :                 if ((property_info_ptr = zend_hash_find_ptr(&ce->properties_info, name)) != NULL &&
    3627           0 :                     (property_info_ptr->flags & ZEND_ACC_STATIC) != 0) {
    3628           0 :                         property_info->offset = property_info_ptr->offset;
    3629           0 :                         zval_ptr_dtor(&ce->default_static_members_table[property_info->offset]);
    3630           0 :                         zend_hash_del(&ce->properties_info, name);
    3631             :                 } else {
    3632         501 :                         property_info->offset = ce->default_static_members_count++;
    3633         501 :                         ce->default_static_members_table = perealloc(ce->default_static_members_table, sizeof(zval) * ce->default_static_members_count, ce->type == ZEND_INTERNAL_CLASS);
    3634             :                 }
    3635         501 :                 ZVAL_COPY_VALUE(&ce->default_static_members_table[property_info->offset], property);
    3636         501 :                 if (ce->type == ZEND_USER_CLASS) {
    3637         501 :                         ce->static_members_table = ce->default_static_members_table;
    3638             :                 }
    3639             :         } else {
    3640     4047168 :                 if ((property_info_ptr = zend_hash_find_ptr(&ce->properties_info, name)) != NULL &&
    3641       94016 :                     (property_info_ptr->flags & ZEND_ACC_STATIC) == 0) {
    3642       94016 :                         property_info->offset = property_info_ptr->offset;
    3643       94016 :                         zval_ptr_dtor(&ce->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)]);
    3644       94016 :                         zend_hash_del(&ce->properties_info, name);
    3645             :                 } else {
    3646     1835552 :                         property_info->offset = OBJ_PROP_TO_OFFSET(ce->default_properties_count);
    3647     1835552 :                         ce->default_properties_count++;
    3648     1835552 :                         ce->default_properties_table = perealloc(ce->default_properties_table, sizeof(zval) * ce->default_properties_count, ce->type == ZEND_INTERNAL_CLASS);
    3649             :                 }
    3650     1929568 :                 ZVAL_COPY_VALUE(&ce->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)], property);
    3651             :         }
    3652     1930069 :         if (ce->type & ZEND_INTERNAL_CLASS) {
    3653     1927328 :                 switch(Z_TYPE_P(property)) {
    3654             :                         case IS_ARRAY:
    3655             :                         case IS_OBJECT:
    3656             :                         case IS_RESOURCE:
    3657           0 :                                 zend_error_noreturn(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources");
    3658             :                                 break;
    3659             :                         default:
    3660             :                                 break;
    3661             :                 }
    3662             :         }
    3663     1930069 :         if (access_type & ZEND_ACC_PUBLIC) {
    3664     1529246 :                 property_info->name = zend_string_copy(name);
    3665      400823 :         } else if (access_type & ZEND_ACC_PRIVATE) {
    3666      141873 :                 property_info->name = zend_mangle_property_name(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), ZSTR_VAL(name), ZSTR_LEN(name), ce->type & ZEND_INTERNAL_CLASS);
    3667             :         } else {
    3668             :                 ZEND_ASSERT(access_type & ZEND_ACC_PROTECTED);
    3669      258950 :                 property_info->name = zend_mangle_property_name("*", 1, ZSTR_VAL(name), ZSTR_LEN(name), ce->type & ZEND_INTERNAL_CLASS);
    3670             :         }
    3671             : 
    3672     1930069 :         property_info->name = zend_new_interned_string(property_info->name);
    3673     1930069 :         property_info->flags = access_type;
    3674     1930069 :         property_info->doc_comment = doc_comment;
    3675     1930069 :         property_info->ce = ce;
    3676     1930069 :         zend_hash_update_ptr(&ce->properties_info, name, property_info);
    3677             : 
    3678     1930069 :         return SUCCESS;
    3679             : }
    3680             : /* }}} */
    3681             : 
    3682     1927328 : ZEND_API int zend_declare_property(zend_class_entry *ce, const char *name, size_t name_length, zval *property, int access_type) /* {{{ */
    3683             : {
    3684     3854656 :         zend_string *key = zend_string_init(name, name_length, ce->type & ZEND_INTERNAL_CLASS);
    3685     1927328 :         int ret = zend_declare_property_ex(ce, key, property, access_type, NULL);
    3686             :         zend_string_release(key);
    3687     1927328 :         return ret;
    3688             : }
    3689             : /* }}} */
    3690             : 
    3691     1292720 : ZEND_API int zend_declare_property_null(zend_class_entry *ce, const char *name, size_t name_length, int access_type) /* {{{ */
    3692             : {
    3693             :         zval property;
    3694             : 
    3695     1292720 :         ZVAL_NULL(&property);
    3696     1292720 :         return zend_declare_property(ce, name, name_length, &property, access_type);
    3697             : }
    3698             : /* }}} */
    3699             : 
    3700           0 : ZEND_API int zend_declare_property_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type) /* {{{ */
    3701             : {
    3702             :         zval property;
    3703             : 
    3704           0 :         ZVAL_BOOL(&property, value);
    3705           0 :         return zend_declare_property(ce, name, name_length, &property, access_type);
    3706             : }
    3707             : /* }}} */
    3708             : 
    3709      117520 : ZEND_API int zend_declare_property_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type) /* {{{ */
    3710             : {
    3711             :         zval property;
    3712             : 
    3713      117520 :         ZVAL_LONG(&property, value);
    3714      117520 :         return zend_declare_property(ce, name, name_length, &property, access_type);
    3715             : }
    3716             : /* }}} */
    3717             : 
    3718           0 : ZEND_API int zend_declare_property_double(zend_class_entry *ce, const char *name, size_t name_length, double value, int access_type) /* {{{ */
    3719             : {
    3720             :         zval property;
    3721             : 
    3722           0 :         ZVAL_DOUBLE(&property, value);
    3723           0 :         return zend_declare_property(ce, name, name_length, &property, access_type);
    3724             : }
    3725             : /* }}} */
    3726             : 
    3727      517088 : ZEND_API int zend_declare_property_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value, int access_type) /* {{{ */
    3728             : {
    3729             :         zval property;
    3730             : 
    3731     1034176 :         ZVAL_NEW_STR(&property, zend_string_init(value, strlen(value), ce->type & ZEND_INTERNAL_CLASS));
    3732      517088 :         return zend_declare_property(ce, name, name_length, &property, access_type);
    3733             : }
    3734             : /* }}} */
    3735             : 
    3736           0 : ZEND_API int zend_declare_property_stringl(zend_class_entry *ce, const char *name, size_t name_length, const char *value, size_t value_len, int access_type) /* {{{ */
    3737             : {
    3738             :         zval property;
    3739             : 
    3740           0 :         ZVAL_NEW_STR(&property, zend_string_init(value, value_len, ce->type & ZEND_INTERNAL_CLASS));
    3741           0 :         return zend_declare_property(ce, name, name_length, &property, access_type);
    3742             : }
    3743             : /* }}} */
    3744             : 
    3745    25126146 : ZEND_API int zend_declare_class_constant_ex(zend_class_entry *ce, zend_string *name, zval *value, int access_type, zend_string *doc_comment) /* {{{ */
    3746             : {
    3747             :         zend_class_constant *c;
    3748             : 
    3749    25126146 :         if (ce->ce_flags & ZEND_ACC_INTERFACE) {
    3750          21 :                 if (access_type != ZEND_ACC_PUBLIC) {
    3751           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface constant %s::%s must be public", ZSTR_VAL(ce->name), ZSTR_VAL(name));
    3752             :                 }
    3753             :         }
    3754             : 
    3755    25126144 :         if (zend_string_equals_literal_ci(name, "class")) {
    3756           1 :                 zend_error_noreturn(ce->type == ZEND_INTERNAL_CLASS ? E_CORE_ERROR : E_COMPILE_ERROR,
    3757             :                                 "A class constant must not be called 'class'; it is reserved for class name fetching");
    3758             :         }
    3759             : 
    3760    25126143 :         if (ce->type == ZEND_INTERNAL_CLASS) {
    3761    25125776 :                 c = pemalloc(sizeof(zend_class_constant), 1);
    3762             :         } else {
    3763         367 :                 c = zend_arena_alloc(&CG(arena), sizeof(zend_class_constant));
    3764             :         }
    3765    25126143 :         ZVAL_COPY_VALUE(&c->value, value);
    3766    25126143 :         Z_ACCESS_FLAGS(c->value) = access_type;
    3767    25126143 :         c->doc_comment = doc_comment;
    3768    25126143 :         c->ce = ce;
    3769    25126143 :         if (Z_CONSTANT_P(value)) {
    3770          32 :                 ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
    3771             :         }
    3772             : 
    3773    50252286 :         if (!zend_hash_add_ptr(&ce->constants_table, name, c)) {
    3774           4 :                 zend_error_noreturn(ce->type == ZEND_INTERNAL_CLASS ? E_CORE_ERROR : E_COMPILE_ERROR,
    3775           2 :                         "Cannot redefine class constant %s::%s", ZSTR_VAL(ce->name), ZSTR_VAL(name));
    3776             :         }
    3777             : 
    3778    25126141 :         return SUCCESS;
    3779             : }
    3780             : /* }}} */
    3781             : 
    3782    25125776 : ZEND_API int zend_declare_class_constant(zend_class_entry *ce, const char *name, size_t name_length, zval *value) /* {{{ */
    3783             : {
    3784             :         int ret;
    3785             : 
    3786    50251552 :         zend_string *key = zend_string_init(name, name_length, ce->type & ZEND_INTERNAL_CLASS);
    3787    25125776 :         ret = zend_declare_class_constant_ex(ce, key, value, ZEND_ACC_PUBLIC, NULL);
    3788             :         zend_string_release(key);
    3789    25125776 :         return ret;
    3790             : }
    3791             : /* }}} */
    3792             : 
    3793       23504 : ZEND_API int zend_declare_class_constant_null(zend_class_entry *ce, const char *name, size_t name_length) /* {{{ */
    3794             : {
    3795             :         zval constant;
    3796             : 
    3797       23504 :         ZVAL_NULL(&constant);
    3798       23504 :         return zend_declare_class_constant(ce, name, name_length, &constant);
    3799             : }
    3800             : /* }}} */
    3801             : 
    3802    24585184 : ZEND_API int zend_declare_class_constant_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value) /* {{{ */
    3803             : {
    3804             :         zval constant;
    3805             : 
    3806    24585184 :         ZVAL_LONG(&constant, value);
    3807    24585184 :         return zend_declare_class_constant(ce, name, name_length, &constant);
    3808             : }
    3809             : /* }}} */
    3810             : 
    3811           0 : ZEND_API int zend_declare_class_constant_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_bool value) /* {{{ */
    3812             : {
    3813             :         zval constant;
    3814             : 
    3815           0 :         ZVAL_BOOL(&constant, value);
    3816           0 :         return zend_declare_class_constant(ce, name, name_length, &constant);
    3817             : }
    3818             : /* }}} */
    3819             : 
    3820       23504 : ZEND_API int zend_declare_class_constant_double(zend_class_entry *ce, const char *name, size_t name_length, double value) /* {{{ */
    3821             : {
    3822             :         zval constant;
    3823             : 
    3824       23504 :         ZVAL_DOUBLE(&constant, value);
    3825       23504 :         return zend_declare_class_constant(ce, name, name_length, &constant);
    3826             : }
    3827             : /* }}} */
    3828             : 
    3829      493584 : ZEND_API int zend_declare_class_constant_stringl(zend_class_entry *ce, const char *name, size_t name_length, const char *value, size_t value_length) /* {{{ */
    3830             : {
    3831             :         zval constant;
    3832             : 
    3833      987168 :         ZVAL_NEW_STR(&constant, zend_string_init(value, value_length, ce->type & ZEND_INTERNAL_CLASS));
    3834      493584 :         return zend_declare_class_constant(ce, name, name_length, &constant);
    3835             : }
    3836             : /* }}} */
    3837             : 
    3838      188032 : ZEND_API int zend_declare_class_constant_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value) /* {{{ */
    3839             : {
    3840      188032 :         return zend_declare_class_constant_stringl(ce, name, name_length, value, strlen(value));
    3841             : }
    3842             : /* }}} */
    3843             : 
    3844       14305 : ZEND_API void zend_update_property_ex(zend_class_entry *scope, zval *object, zend_string *name, zval *value) /* {{{ */
    3845             : {
    3846             :         zval property;
    3847       14305 :         zend_class_entry *old_scope = EG(fake_scope);
    3848             : 
    3849       14305 :         EG(fake_scope) = scope;
    3850             : 
    3851       14305 :         if (!Z_OBJ_HT_P(object)->write_property) {
    3852           0 :                 zend_error_noreturn(E_CORE_ERROR, "Property %s of class %s cannot be updated", ZSTR_VAL(name), ZSTR_VAL(Z_OBJCE_P(object)->name));
    3853             :         }
    3854       14305 :         ZVAL_STR(&property, name);
    3855       14305 :         Z_OBJ_HT_P(object)->write_property(object, &property, value, NULL);
    3856             : 
    3857       14305 :         EG(fake_scope) = old_scope;
    3858       14305 : }
    3859             : /* }}} */
    3860             : 
    3861        1911 : ZEND_API void zend_update_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zval *value) /* {{{ */
    3862             : {
    3863             :         zval property;
    3864        1911 :         zend_class_entry *old_scope = EG(fake_scope);
    3865             : 
    3866        1911 :         EG(fake_scope) = scope;
    3867             : 
    3868        1911 :         if (!Z_OBJ_HT_P(object)->write_property) {
    3869           0 :                 zend_error_noreturn(E_CORE_ERROR, "Property %s of class %s cannot be updated", name, ZSTR_VAL(Z_OBJCE_P(object)->name));
    3870             :         }
    3871        3822 :         ZVAL_STRINGL(&property, name, name_length);
    3872        1911 :         Z_OBJ_HT_P(object)->write_property(object, &property, value, NULL);
    3873        1911 :         zval_ptr_dtor(&property);
    3874             : 
    3875        1911 :         EG(fake_scope) = old_scope;
    3876        1911 : }
    3877             : /* }}} */
    3878             : 
    3879           0 : ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, const char *name, size_t name_length) /* {{{ */
    3880             : {
    3881             :         zval tmp;
    3882             : 
    3883           0 :         ZVAL_NULL(&tmp);
    3884           0 :         zend_update_property(scope, object, name, name_length, &tmp);
    3885           0 : }
    3886             : /* }}} */
    3887             : 
    3888           0 : ZEND_API void zend_update_property_bool(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value) /* {{{ */
    3889             : {
    3890             :         zval tmp;
    3891             : 
    3892           0 :         ZVAL_BOOL(&tmp, value);
    3893           0 :         zend_update_property(scope, object, name, name_length, &tmp);
    3894           0 : }
    3895             : /* }}} */
    3896             : 
    3897           6 : ZEND_API void zend_update_property_long(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value) /* {{{ */
    3898             : {
    3899             :         zval tmp;
    3900             : 
    3901           6 :         ZVAL_LONG(&tmp, value);
    3902           6 :         zend_update_property(scope, object, name, name_length, &tmp);
    3903           6 : }
    3904             : /* }}} */
    3905             : 
    3906           0 : ZEND_API void zend_update_property_double(zend_class_entry *scope, zval *object, const char *name, size_t name_length, double value) /* {{{ */
    3907             : {
    3908             :         zval tmp;
    3909             : 
    3910           0 :         ZVAL_DOUBLE(&tmp, value);
    3911           0 :         zend_update_property(scope, object, name, name_length, &tmp);
    3912           0 : }
    3913             : /* }}} */
    3914             : 
    3915          31 : ZEND_API void zend_update_property_str(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_string *value) /* {{{ */
    3916             : {
    3917             :         zval tmp;
    3918             : 
    3919          31 :         ZVAL_STR(&tmp, value);
    3920          31 :         zend_update_property(scope, object, name, name_length, &tmp);
    3921          31 : }
    3922             : /* }}} */
    3923             : 
    3924         559 : ZEND_API void zend_update_property_string(zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value) /* {{{ */
    3925             : {
    3926             :         zval tmp;
    3927             : 
    3928        1118 :         ZVAL_STRING(&tmp, value);
    3929             :         Z_SET_REFCOUNT(tmp, 0);
    3930         559 :         zend_update_property(scope, object, name, name_length, &tmp);
    3931         559 : }
    3932             : /* }}} */
    3933             : 
    3934           0 : ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value, size_t value_len) /* {{{ */
    3935             : {
    3936             :         zval tmp;
    3937             : 
    3938           0 :         ZVAL_STRINGL(&tmp, value, value_len);
    3939             :         Z_SET_REFCOUNT(tmp, 0);
    3940           0 :         zend_update_property(scope, object, name, name_length, &tmp);
    3941           0 : }
    3942             : /* }}} */
    3943             : 
    3944           0 : ZEND_API int zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value) /* {{{ */
    3945             : {
    3946             :         zval *property;
    3947           0 :         zend_class_entry *old_scope = EG(fake_scope);
    3948           0 :         zend_string *key = zend_string_init(name, name_length, 0);
    3949             : 
    3950           0 :         EG(fake_scope) = scope;
    3951           0 :         property = zend_std_get_static_property(scope, key, 0);
    3952           0 :         EG(fake_scope) = old_scope;
    3953             :         zend_string_free(key);
    3954           0 :         if (!property) {
    3955           0 :                 return FAILURE;
    3956             :         } else {
    3957           0 :                 if (property != value) {
    3958           0 :                         if (Z_ISREF_P(property)) {
    3959             :                                 zval_dtor(property);
    3960           0 :                                 ZVAL_COPY_VALUE(property, value);
    3961           0 :                                 if (Z_REFCOUNTED_P(value) && Z_REFCOUNT_P(value) > 0) {
    3962             :                                         zval_opt_copy_ctor(property);
    3963             :                                 }
    3964             :                         } else {
    3965             :                                 zval garbage;
    3966             : 
    3967           0 :                                 ZVAL_COPY_VALUE(&garbage, property);
    3968           0 :                                 if (Z_REFCOUNTED_P(value)) {
    3969             :                                         Z_ADDREF_P(value);
    3970           0 :                                         if (Z_ISREF_P(value)) {
    3971           0 :                                                 SEPARATE_ZVAL(value);
    3972             :                                         }
    3973             :                                 }
    3974           0 :                                 ZVAL_COPY_VALUE(property, value);
    3975           0 :                                 zval_ptr_dtor(&garbage);
    3976             :                         }
    3977             :                 }
    3978           0 :                 return SUCCESS;
    3979             :         }
    3980             : }
    3981             : /* }}} */
    3982             : 
    3983           0 : ZEND_API int zend_update_static_property_null(zend_class_entry *scope, const char *name, size_t name_length) /* {{{ */
    3984             : {
    3985             :         zval tmp;
    3986             : 
    3987           0 :         ZVAL_NULL(&tmp);
    3988           0 :         return zend_update_static_property(scope, name, name_length, &tmp);
    3989             : }
    3990             : /* }}} */
    3991             : 
    3992           0 : ZEND_API int zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value) /* {{{ */
    3993             : {
    3994             :         zval tmp;
    3995             : 
    3996           0 :         ZVAL_BOOL(&tmp, value);
    3997           0 :         return zend_update_static_property(scope, name, name_length, &tmp);
    3998             : }
    3999             : /* }}} */
    4000             : 
    4001           0 : ZEND_API int zend_update_static_property_long(zend_class_entry *scope, const char *name, size_t name_length, zend_long value) /* {{{ */
    4002             : {
    4003             :         zval tmp;
    4004             : 
    4005           0 :         ZVAL_LONG(&tmp, value);
    4006           0 :         return zend_update_static_property(scope, name, name_length, &tmp);
    4007             : }
    4008             : /* }}} */
    4009             : 
    4010           0 : ZEND_API int zend_update_static_property_double(zend_class_entry *scope, const char *name, size_t name_length, double value) /* {{{ */
    4011             : {
    4012             :         zval tmp;
    4013             : 
    4014           0 :         ZVAL_DOUBLE(&tmp, value);
    4015           0 :         return zend_update_static_property(scope, name, name_length, &tmp);
    4016             : }
    4017             : /* }}} */
    4018             : 
    4019           0 : ZEND_API int zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value) /* {{{ */
    4020             : {
    4021             :         zval tmp;
    4022             : 
    4023           0 :         ZVAL_STRING(&tmp, value);
    4024             :         Z_SET_REFCOUNT(tmp, 0);
    4025           0 :         return zend_update_static_property(scope, name, name_length, &tmp);
    4026             : }
    4027             : /* }}} */
    4028             : 
    4029           0 : ZEND_API int zend_update_static_property_stringl(zend_class_entry *scope, const char *name, size_t name_length, const char *value, size_t value_len) /* {{{ */
    4030             : {
    4031             :         zval tmp;
    4032             : 
    4033           0 :         ZVAL_STRINGL(&tmp, value, value_len);
    4034             :         Z_SET_REFCOUNT(tmp, 0);
    4035           0 :         return zend_update_static_property(scope, name, name_length, &tmp);
    4036             : }
    4037             : /* }}} */
    4038             : 
    4039        7025 : ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zval *object, zend_string *name, zend_bool silent, zval *rv) /* {{{ */
    4040             : {
    4041             :         zval property, *value;
    4042        7025 :         zend_class_entry *old_scope = EG(fake_scope);
    4043             : 
    4044        7025 :         EG(fake_scope) = scope;
    4045             : 
    4046        7025 :         if (!Z_OBJ_HT_P(object)->read_property) {
    4047           0 :                 zend_error_noreturn(E_CORE_ERROR, "Property %s of class %s cannot be read", ZSTR_VAL(name), ZSTR_VAL(Z_OBJCE_P(object)->name));
    4048             :         }
    4049             : 
    4050        7025 :         ZVAL_STR(&property, name);
    4051        7025 :         value = Z_OBJ_HT_P(object)->read_property(object, &property, silent?BP_VAR_IS:BP_VAR_R, NULL, rv);
    4052             : 
    4053        7025 :         EG(fake_scope) = old_scope;
    4054        7025 :         return value;
    4055             : }
    4056             : /* }}} */
    4057             : 
    4058         105 : ZEND_API zval *zend_read_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_bool silent, zval *rv) /* {{{ */
    4059             : {
    4060             :         zval *value;
    4061             :         zend_string *str;
    4062             : 
    4063         105 :         str = zend_string_init(name, name_length, 0);
    4064         105 :         value = zend_read_property_ex(scope, object, str, silent, rv);
    4065             :         zend_string_release(str);
    4066         105 :         return value;
    4067             : }
    4068             : /* }}} */
    4069             : 
    4070           0 : ZEND_API zval *zend_read_static_property(zend_class_entry *scope, const char *name, size_t name_length, zend_bool silent) /* {{{ */
    4071             : {
    4072             :         zval *property;
    4073           0 :         zend_class_entry *old_scope = EG(fake_scope);
    4074           0 :         zend_string *key = zend_string_init(name, name_length, 0);
    4075             : 
    4076           0 :         EG(fake_scope) = scope;
    4077           0 :         property = zend_std_get_static_property(scope, key, silent);
    4078           0 :         EG(fake_scope) = old_scope;
    4079             :         zend_string_free(key);
    4080             : 
    4081           0 :         return property;
    4082             : }
    4083             : /* }}} */
    4084             : 
    4085      193663 : ZEND_API void zend_save_error_handling(zend_error_handling *current) /* {{{ */
    4086             : {
    4087      193663 :         current->handling = EG(error_handling);
    4088      193663 :         current->exception = EG(exception_class);
    4089      193663 :         ZVAL_COPY(&current->user_handler, &EG(user_error_handler));
    4090      193663 : }
    4091             : /* }}} */
    4092             : 
    4093      193663 : ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling, zend_class_entry *exception_class, zend_error_handling *current) /* {{{ */
    4094             : {
    4095      193663 :         if (current) {
    4096      193663 :                 zend_save_error_handling(current);
    4097      387326 :                 if (error_handling != EH_NORMAL && Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
    4098           8 :                         zval_ptr_dtor(&EG(user_error_handler));
    4099           8 :                         ZVAL_UNDEF(&EG(user_error_handler));
    4100             :                 }
    4101             :         }
    4102      193663 :         EG(error_handling) = error_handling;
    4103      193663 :         EG(exception_class) = error_handling == EH_THROW ? exception_class : NULL;
    4104      193663 : }
    4105             : /* }}} */
    4106             : 
    4107           8 : static int same_zval(zval *zv1, zval *zv2)  /* {{{ */
    4108             : {
    4109           8 :         if (Z_TYPE_P(zv1) != Z_TYPE_P(zv2)) {
    4110           8 :                 return 0;
    4111             :         }
    4112           0 :         switch (Z_TYPE_P(zv1)) {
    4113             :                 case IS_UNDEF:
    4114             :                 case IS_NULL:
    4115             :                 case IS_FALSE:
    4116             :                 case IS_TRUE:
    4117           0 :                         return 1;
    4118             :                 case IS_LONG:
    4119           0 :                         return Z_LVAL_P(zv1) == Z_LVAL_P(zv2);
    4120             :                 case IS_DOUBLE:
    4121           0 :                         return Z_LVAL_P(zv1) == Z_LVAL_P(zv2);
    4122             :                 case IS_STRING:
    4123             :                 case IS_ARRAY:
    4124             :                 case IS_OBJECT:
    4125             :                 case IS_RESOURCE:
    4126           0 :                         return Z_COUNTED_P(zv1) == Z_COUNTED_P(zv2);
    4127             :                 default:
    4128           0 :                         return 0;
    4129             :         }
    4130             : }
    4131             : /* }}} */
    4132             : 
    4133      193663 : ZEND_API void zend_restore_error_handling(zend_error_handling *saved) /* {{{ */
    4134             : {
    4135      193663 :         EG(error_handling) = saved->handling;
    4136      193663 :         EG(exception_class) = saved->handling == EH_THROW ? saved->exception : NULL;
    4137      387342 :         if (Z_TYPE(saved->user_handler) != IS_UNDEF
    4138           8 :                 && !same_zval(&saved->user_handler, &EG(user_error_handler))) {
    4139           8 :                 zval_ptr_dtor(&EG(user_error_handler));
    4140           8 :                 ZVAL_COPY_VALUE(&EG(user_error_handler), &saved->user_handler);
    4141      387310 :         } else if (Z_TYPE(saved->user_handler)) {
    4142           0 :                 zval_ptr_dtor(&saved->user_handler);
    4143             :         }
    4144      193663 :         ZVAL_UNDEF(&saved->user_handler);
    4145      193663 : }
    4146             : /* }}} */
    4147             : 
    4148          10 : ZEND_API zend_string* zend_find_alias_name(zend_class_entry *ce, zend_string *name) /* {{{ */
    4149             : {
    4150             :         zend_trait_alias *alias, **alias_ptr;
    4151             : 
    4152          10 :         if ((alias_ptr = ce->trait_aliases)) {
    4153           9 :                 alias = *alias_ptr;
    4154          19 :                 while (alias) {
    4155          10 :                         if (alias->alias && zend_string_equals_ci(alias->alias, name)) {
    4156           9 :                                 return alias->alias;
    4157             :                         }
    4158           1 :                         alias_ptr++;
    4159           1 :                         alias = *alias_ptr;
    4160             :                 }
    4161             :         }
    4162             : 
    4163           1 :         return name;
    4164             : }
    4165             : /* }}} */
    4166             : 
    4167          14 : ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_function *f) /* {{{ */
    4168             : {
    4169             :         zend_function *func;
    4170             :         HashTable *function_table;
    4171             :         zend_string *name;
    4172             : 
    4173          68 :         if (f->common.type != ZEND_USER_FUNCTION ||
    4174          28 :             (f->op_array.refcount && *(f->op_array.refcount) < 2) ||
    4175          13 :             !f->common.scope ||
    4176          13 :             !f->common.scope->trait_aliases) {
    4177           1 :                 return f->common.function_name;
    4178             :         }
    4179             : 
    4180          13 :         function_table = &ce->function_table;
    4181          42 :         ZEND_HASH_FOREACH_STR_KEY_PTR(function_table, name, func) {
    4182          21 :                 if (func == f) {
    4183          13 :                         if (!name) {
    4184           0 :                                 return f->common.function_name;
    4185             :                         }
    4186          19 :                         if (ZSTR_LEN(name) == ZSTR_LEN(f->common.function_name) &&
    4187           6 :                             !strncasecmp(ZSTR_VAL(name), ZSTR_VAL(f->common.function_name), ZSTR_LEN(f->common.function_name))) {
    4188           6 :                                 return f->common.function_name;
    4189             :                         }
    4190           7 :                         return zend_find_alias_name(f->common.scope, name);
    4191             :                 }
    4192             :         } ZEND_HASH_FOREACH_END();
    4193           0 :         return f->common.function_name;
    4194             : }
    4195             : /* }}} */
    4196             : 
    4197          12 : ZEND_API const char *zend_get_object_type(const zend_class_entry *ce) /* {{{ */
    4198             : {
    4199          12 :         if(ce->ce_flags & ZEND_ACC_TRAIT) {
    4200           3 :                 return "trait";
    4201           9 :         } else if (ce->ce_flags & ZEND_ACC_INTERFACE) {
    4202           4 :                 return "interface";
    4203             :         } else {
    4204           5 :                 return "class";
    4205             :         }
    4206             : }
    4207             : /* }}} */
    4208             : 
    4209          13 : ZEND_API zend_bool zend_is_iterable(zval *iterable) /* {{{ */
    4210             : {
    4211          13 :         switch (Z_TYPE_P(iterable)) {
    4212             :                 case IS_ARRAY:
    4213           3 :                         return 1;
    4214             :                 case IS_OBJECT:
    4215           6 :                         return instanceof_function(Z_OBJCE_P(iterable), zend_ce_traversable);
    4216             :                 default:
    4217           4 :                         return 0;
    4218             :         }
    4219             : }
    4220             : /* }}} */
    4221             : 
    4222             : /*
    4223             :  * Local variables:
    4224             :  * tab-width: 4
    4225             :  * c-basic-offset: 4
    4226             :  * indent-tabs-mode: t
    4227             :  * End:
    4228             :  */

Generated by: LCOV version 1.10

Generated at Sun, 28 Aug 2016 17:09:58 +0000 (21 hours ago)

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