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: 1503 1960 76.7 %
Date: 2015-01-26 Functions: 124 167 74.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Mon, 26 Jan 2015 14:46:42 +0000 (6 days ago)

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