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: 1566 2080 75.3 %
Date: 2015-07-31 Functions: 129 178 72.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Fri, 31 Jul 2015 08:58:46 +0000 (22 hours ago)

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