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: 1570 2081 75.4 %
Date: 2015-08-29 Functions: 128 177 72.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Sat, 29 Aug 2015 10:22:12 +0000 (44 hours ago)

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