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

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

Generated by: LCOV version 1.10

Generated at Wed, 22 Oct 2014 07:24:46 +0000 (18 hours ago)

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