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

Generated by: LCOV version 1.10

Generated at Tue, 22 Jul 2014 01:33:07 +0000 (9 days ago)

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