PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

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

Generated by: LCOV version 1.10

Generated at Sat, 27 Sep 2014 16:43:06 +0000 (4 days ago)

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