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

Generated by: LCOV version 1.10

Generated at Thu, 16 Oct 2014 05:26:58 +0000 (4 days ago)

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