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: 1400 1847 75.8 %
Date: 2014-07-13 Functions: 106 141 75.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Sun, 13 Jul 2014 23:57:44 +0000 (9 days ago)

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