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: 1598 2107 75.8 %
Date: 2016-04-27 Functions: 129 178 72.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Wed, 27 Apr 2016 15:51:37 +0000 (6 days ago)

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