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: 1571 2062 76.2 %
Date: 2014-12-13 Functions: 125 168 74.4 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Sat, 13 Dec 2014 06:16:10 +0000 (8 days ago)

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