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_object_handlers.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 721 775 93.0 %
Date: 2014-09-27 Functions: 36 37 97.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #include "zend.h"
      23             : #include "zend_globals.h"
      24             : #include "zend_variables.h"
      25             : #include "zend_API.h"
      26             : #include "zend_objects.h"
      27             : #include "zend_objects_API.h"
      28             : #include "zend_object_handlers.h"
      29             : #include "zend_interfaces.h"
      30             : #include "zend_closures.h"
      31             : #include "zend_compile.h"
      32             : #include "zend_hash.h"
      33             : 
      34             : #define DEBUG_OBJECT_HANDLERS 0
      35             : 
      36             : /* guard flags */
      37             : #define IN_GET          (1<<0)
      38             : #define IN_SET          (1<<1)
      39             : #define IN_UNSET        (1<<2)
      40             : #define IN_ISSET        (1<<3)
      41             : 
      42             : #define Z_OBJ_PROTECT_RECURSION(zval_p) \
      43             :         do { \
      44             :                 if (Z_OBJ_APPLY_COUNT_P(zval_p) >= 3) { \
      45             :                         zend_error(E_ERROR, "Nesting level too deep - recursive dependency?"); \
      46             :                 } \
      47             :                 Z_OBJ_INC_APPLY_COUNT_P(zval_p); \
      48             :         } while (0)
      49             : 
      50             : 
      51             : #define Z_OBJ_UNPROTECT_RECURSION(zval_p) \
      52             :         Z_OBJ_DEC_APPLY_COUNT_P(zval_p)
      53             : 
      54             : /*
      55             :   __X accessors explanation:
      56             : 
      57             :   if we have __get and property that is not part of the properties array is
      58             :   requested, we call __get handler. If it fails, we return uninitialized.
      59             : 
      60             :   if we have __set and property that is not part of the properties array is
      61             :   set, we call __set handler. If it fails, we do not change the array.
      62             : 
      63             :   for both handlers above, when we are inside __get/__set, no further calls for
      64             :   __get/__set for this property of this object will be made, to prevent endless
      65             :   recursion and enable accessors to change properties array.
      66             : 
      67             :   if we have __call and method which is not part of the class function table is
      68             :   called, we cal __call handler.
      69             : */
      70             : 
      71      215980 : ZEND_API void rebuild_object_properties(zend_object *zobj) /* {{{ */
      72             : {
      73      215980 :         if (!zobj->properties) {
      74             :                 zend_property_info *prop_info;
      75      215980 :                 zend_class_entry *ce = zobj->ce;
      76             : 
      77      215980 :                 ALLOC_HASHTABLE(zobj->properties);
      78      215980 :                 zend_hash_init(zobj->properties, ce->default_properties_count, NULL, ZVAL_PTR_DTOR, 0);
      79      215980 :                 if (ce->default_properties_count) {
      80       47408 :                         ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) {
      81       52686 :                                 if (/*prop_info->ce == ce &&*/
      82       17580 :                                     (prop_info->flags & ZEND_ACC_STATIC) == 0 &&
      83       17553 :                                     prop_info->offset >= 0 &&
      84       17553 :                                     Z_TYPE(zobj->properties_table[prop_info->offset]) != IS_UNDEF) {
      85             :                                         zval zv;
      86             : 
      87       17541 :                                         ZVAL_INDIRECT(&zv, &zobj->properties_table[prop_info->offset]);
      88       17541 :                                         zend_hash_add_new(zobj->properties, prop_info->name, &zv);
      89             :                                 }
      90             :                         } ZEND_HASH_FOREACH_END();
      91       25477 :                         while (ce->parent && ce->parent->default_properties_count) {
      92        1005 :                                 ce = ce->parent;
      93        9821 :                                 ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) {
      94       15755 :                                         if (prop_info->ce == ce &&
      95        4176 :                                             (prop_info->flags & ZEND_ACC_STATIC) == 0 &&
      96        4165 :                                             (prop_info->flags & ZEND_ACC_PRIVATE) != 0 &&
      97        1503 :                                             prop_info->offset >= 0 &&
      98        1503 :                                                 Z_TYPE(zobj->properties_table[prop_info->offset]) != IS_UNDEF) {
      99             :                                                 zval zv;
     100             :                                                 
     101        1501 :                                                 ZVAL_INDIRECT(&zv, &zobj->properties_table[prop_info->offset]);
     102        1501 :                                                 zend_hash_add(zobj->properties, prop_info->name, &zv);
     103             :                                         }
     104             :                                 } ZEND_HASH_FOREACH_END();
     105             :                         }
     106             :                 }
     107             :         }
     108      215980 : }
     109             : /* }}} */
     110             : 
     111      283273 : ZEND_API HashTable *zend_std_get_properties(zval *object TSRMLS_DC) /* {{{ */
     112             : {
     113             :         zend_object *zobj;
     114      283273 :         zobj = Z_OBJ_P(object);
     115      283273 :         if (!zobj->properties) {
     116      200803 :                 rebuild_object_properties(zobj);
     117             :         }
     118      283273 :         return zobj->properties;
     119             : }
     120             : /* }}} */
     121             : 
     122      708732 : ZEND_API HashTable *zend_std_get_gc(zval *object, zval **table, int *n TSRMLS_DC) /* {{{ */
     123             : {
     124      708732 :         if (Z_OBJ_HANDLER_P(object, get_properties) != zend_std_get_properties) {
     125           3 :                 *table = NULL;
     126           3 :                 *n = 0;
     127           3 :                 return Z_OBJ_HANDLER_P(object, get_properties)(object TSRMLS_CC);
     128             :         } else {
     129      708729 :                 zend_object *zobj = Z_OBJ_P(object);
     130             : 
     131      708729 :                 *table = zobj->properties_table;
     132      708729 :                 *n = zobj->ce->default_properties_count;
     133      708729 :                 return zobj->properties;
     134             :         }
     135             : }
     136             : /* }}} */
     137             : 
     138        3463 : ZEND_API HashTable *zend_std_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
     139             : {
     140        3463 :         zend_class_entry *ce = Z_OBJCE_P(object);
     141             :         zval retval;
     142             :         HashTable *ht;
     143             : 
     144        3463 :         if (!ce->__debugInfo) {
     145        3451 :                 *is_temp = 0;
     146        6902 :                 return Z_OBJ_HANDLER_P(object, get_properties)
     147        3451 :                         ? Z_OBJ_HANDLER_P(object, get_properties)(object TSRMLS_CC)
     148             :                         : NULL;
     149             :         }
     150             : 
     151          12 :         zend_call_method_with_0_params(object, ce, &ce->__debugInfo, ZEND_DEBUGINFO_FUNC_NAME, &retval);
     152          12 :         if (Z_TYPE(retval) == IS_ARRAY) {
     153           1 :                 if (Z_IMMUTABLE(retval)) {
     154           0 :                         *is_temp = 1;
     155           0 :                         ALLOC_HASHTABLE(ht);
     156           0 :                         zend_array_dup(ht, Z_ARRVAL(retval));
     157           0 :                         return ht;
     158           1 :                 } else if (Z_REFCOUNT(retval) <= 1) {
     159           1 :                         *is_temp = 1;
     160           1 :                         ALLOC_HASHTABLE(ht);
     161           1 :                         *ht = *Z_ARRVAL(retval);
     162           1 :                         efree_size(Z_ARR(retval), sizeof(zend_array));
     163           1 :                         return ht;
     164             :                 } else {
     165           0 :                         *is_temp = 0;
     166           0 :                         zval_ptr_dtor(&retval);
     167           0 :                         return Z_ARRVAL(retval);
     168             :                 }
     169          11 :         } else if (Z_TYPE(retval) == IS_NULL) {
     170           1 :                 *is_temp = 1;
     171           1 :                 ALLOC_HASHTABLE(ht);
     172           1 :                 zend_hash_init(ht, 0, NULL, ZVAL_PTR_DTOR, 0);
     173           1 :                 return ht;
     174             :         }
     175             : 
     176          10 :         zend_error_noreturn(E_ERROR, ZEND_DEBUGINFO_FUNC_NAME "() must return an array");
     177             : 
     178             :         return NULL; /* Compilers are dumb and don't understand that noreturn means that the function does NOT need a return value... */
     179             : }
     180             : /* }}} */
     181             : 
     182         135 : static void zend_std_call_getter(zval *object, zval *member, zval *retval TSRMLS_DC) /* {{{ */
     183             : {
     184         135 :         zend_class_entry *ce = Z_OBJCE_P(object);
     185             : 
     186             :         /* __get handler is called with one argument:
     187             :               property name
     188             : 
     189             :            it should return whether the call was successfull or not
     190             :         */
     191         135 :         if (Z_REFCOUNTED_P(member)) Z_ADDREF_P(member);
     192             : 
     193         135 :         zend_call_method_with_1_params(object, ce, &ce->__get, ZEND_GET_FUNC_NAME, retval, member);
     194             : 
     195         134 :         zval_ptr_dtor(member);
     196         134 : }
     197             : /* }}} */
     198             : 
     199         100 : static int zend_std_call_setter(zval *object, zval *member, zval *value TSRMLS_DC) /* {{{ */
     200             : {
     201             :         zval retval;
     202             :         int result;
     203         100 :         zend_class_entry *ce = Z_OBJCE_P(object);
     204             : 
     205         100 :         if (Z_REFCOUNTED_P(member)) Z_ADDREF_P(member);
     206         100 :         if (Z_REFCOUNTED_P(value)) Z_ADDREF_P(value);
     207             : 
     208             :         /* __set handler is called with two arguments:
     209             :              property name
     210             :              value to be set
     211             : 
     212             :            it should return whether the call was successfull or not
     213             :         */
     214         100 :         zend_call_method_with_2_params(object, ce, &ce->__set, ZEND_SET_FUNC_NAME, &retval, member, value);
     215             : 
     216          99 :         zval_ptr_dtor(member);
     217          99 :         zval_ptr_dtor(value);
     218             : 
     219          99 :         if (Z_TYPE(retval) != IS_UNDEF) {
     220          98 :                 result = i_zend_is_true(&retval TSRMLS_CC) ? SUCCESS : FAILURE;
     221          98 :                 zval_ptr_dtor(&retval);
     222          98 :                 return result;
     223             :         } else {
     224           1 :                 return FAILURE;
     225             :         }
     226             : }
     227             : /* }}} */
     228             : 
     229           8 : static void zend_std_call_unsetter(zval *object, zval *member TSRMLS_DC) /* {{{ */
     230             : {
     231           8 :         zend_class_entry *ce = Z_OBJCE_P(object);
     232             : 
     233             :         /* __unset handler is called with one argument:
     234             :               property name
     235             :         */
     236             : 
     237           8 :         if (Z_REFCOUNTED_P(member)) Z_ADDREF_P(member);
     238             : 
     239           8 :         zend_call_method_with_1_params(object, ce, &ce->__unset, ZEND_UNSET_FUNC_NAME, NULL, member);
     240             : 
     241           7 :         zval_ptr_dtor(member);
     242           7 : }
     243             : /* }}} */
     244             : 
     245          20 : static void zend_std_call_issetter(zval *object, zval *member, zval *retval TSRMLS_DC) /* {{{ */
     246             : {
     247          20 :         zend_class_entry *ce = Z_OBJCE_P(object);
     248             : 
     249             :         /* __isset handler is called with one argument:
     250             :               property name
     251             : 
     252             :            it should return whether the property is set or not
     253             :         */
     254             : 
     255          20 :         if (Z_REFCOUNTED_P(member)) Z_ADDREF_P(member);
     256             : 
     257          20 :         zend_call_method_with_1_params(object, ce, &ce->__isset, ZEND_ISSET_FUNC_NAME, retval, member);
     258             : 
     259          20 :         zval_ptr_dtor(member);
     260          20 : }
     261             : /* }}} */
     262             : 
     263             : static zend_always_inline int zend_verify_property_access(zend_property_info *property_info, zend_class_entry *ce TSRMLS_DC) /* {{{ */
     264             : {
     265       18730 :         switch (property_info->flags & ZEND_ACC_PPP_MASK) {
     266             :                 case ZEND_ACC_PUBLIC:
     267        9132 :                         return 1;
     268             :                 case ZEND_ACC_PROTECTED:
     269        7411 :                         return zend_check_protected(property_info->ce, EG(scope));
     270             :                 case ZEND_ACC_PRIVATE:
     271        2187 :                         if ((ce==EG(scope) || property_info->ce == EG(scope)) && EG(scope)) {
     272        2064 :                                 return 1;
     273             :                         } else {
     274         123 :                                 return 0;
     275             :                         }
     276             :                         break;
     277             :         }
     278           0 :         return 0;
     279             : }
     280             : /* }}} */
     281             : 
     282             : static zend_always_inline zend_bool is_derived_class(zend_class_entry *child_class, zend_class_entry *parent_class) /* {{{ */
     283             : {
     284        6626 :         child_class = child_class->parent;
     285        7942 :         while (child_class) {
     286        3204 :                 if (child_class == parent_class) {
     287        1888 :                         return 1;
     288             :                 }
     289        1316 :                 child_class = child_class->parent;
     290             :         }
     291             : 
     292        4738 :         return 0;
     293             : }
     294             : /* }}} */
     295             : 
     296             : static zend_always_inline struct _zend_property_info *zend_get_property_info_quick(zend_class_entry *ce, zend_string *member, int silent, void **cache_slot TSRMLS_DC) /* {{{ */
     297             : {
     298             :         zend_property_info *property_info;
     299             :         zend_property_info *scope_property_info;
     300      366787 :         zend_bool denied_access = 0;
     301             : 
     302      366787 :         if (cache_slot && EXPECTED(ce == CACHED_PTR_EX(cache_slot))) {
     303      311269 :                 property_info = CACHED_PTR_EX(cache_slot + 1);
     304      311269 :                 if (UNEXPECTED(!property_info)) {
     305       10989 :                         EG(std_property_info).flags = ZEND_ACC_PUBLIC;
     306       10989 :                         EG(std_property_info).name = member;
     307       10989 :                         EG(std_property_info).ce = ce;
     308       10989 :                         EG(std_property_info).offset = -1;
     309       10989 :                         property_info = &EG(std_property_info);
     310             :                 }
     311      311269 :                 return property_info;
     312             :         }
     313             : 
     314       55518 :         if (UNEXPECTED(member->val[0] == '\0')) {
     315          24 :                 if (!silent) {
     316           1 :                         if (member->len == 0) {
     317           1 :                                 zend_error_noreturn(E_ERROR, "Cannot access empty property");
     318             :                         } else {
     319           0 :                                 zend_error_noreturn(E_ERROR, "Cannot access property started with '\\0'");
     320             :                         }
     321             :                 }
     322          23 :                 return NULL;
     323             :         }
     324       55494 :         property_info = NULL;
     325      110988 :         if ((property_info = zend_hash_find_ptr(&ce->properties_info, member)) != NULL) {
     326       19048 :                 if (UNEXPECTED((property_info->flags & ZEND_ACC_SHADOW) != 0)) {
     327             :                         /* if it's a shadow - go to access it's private */
     328        1710 :                         property_info = NULL;
     329             :                 } else {
     330       17338 :                         if (EXPECTED(zend_verify_property_access(property_info, ce TSRMLS_CC) != 0)) {
     331       34427 :                                 if (EXPECTED((property_info->flags & ZEND_ACC_CHANGED) != 0)
     332       17240 :                                         && EXPECTED(!(property_info->flags & ZEND_ACC_PRIVATE))) {
     333             :                                         /* We still need to make sure that we're not in a context
     334             :                                          * where the right property is a different 'statically linked' private
     335             :                                          * continue checking below...
     336             :                                          */
     337             :                                 } else {
     338       17166 :                                         if (UNEXPECTED((property_info->flags & ZEND_ACC_STATIC) != 0) && !silent) {
     339          12 :                                                 zend_error(E_STRICT, "Accessing static property %s::$%s as non static", ce->name->val, member->val);
     340             :                                         }
     341       17166 :                                         if (cache_slot) {
     342        2494 :                                                 CACHE_POLYMORPHIC_PTR_EX(cache_slot, ce, property_info);
     343             :                                         }
     344       17166 :                                         return property_info;
     345             :                                 }
     346             :                         } else {
     347             :                                 /* Try to look in the scope instead */
     348         151 :                                 denied_access = 1;
     349             :                         }
     350             :                 }
     351             :         }
     352       79285 :         if (EG(scope) != ce
     353       34586 :                 && EG(scope)
     354             :                 && is_derived_class(ce, EG(scope))
     355        4667 :                 && (scope_property_info = zend_hash_find_ptr(&EG(scope)->properties_info, member)) != NULL
     356        1704 :                 && scope_property_info->flags & ZEND_ACC_PRIVATE) {
     357        1698 :                 if (cache_slot) {
     358          61 :                         CACHE_POLYMORPHIC_PTR_EX(cache_slot, ce, scope_property_info);
     359             :                 }
     360        1698 :                 return scope_property_info;
     361       36630 :         } else if (property_info) {
     362         141 :                 if (UNEXPECTED(denied_access != 0)) {
     363             :                         /* Information was available, but we were denied access.  Error out. */
     364         131 :                         if (!silent) {
     365          17 :                                 zend_error_noreturn(E_ERROR, "Cannot access %s property %s::$%s", zend_visibility_string(property_info->flags), ce->name->val, member->val);
     366             :                         }
     367         114 :                         return NULL;
     368             :                 } else {
     369             :                         /* fall through, return property_info... */
     370          10 :                         if (cache_slot) {
     371          10 :                                 CACHE_POLYMORPHIC_PTR_EX(cache_slot, ce, property_info);
     372             :                         }
     373             :                 }
     374             :         } else {
     375       36489 :                 if (cache_slot) {
     376        1620 :                         CACHE_POLYMORPHIC_PTR_EX(cache_slot, ce, NULL);
     377             :                 }
     378       36489 :                 EG(std_property_info).flags = ZEND_ACC_PUBLIC;
     379       36489 :                 EG(std_property_info).name = member;
     380       36489 :                 EG(std_property_info).ce = ce;
     381       36489 :                 EG(std_property_info).offset = -1;
     382       36489 :                 property_info = &EG(std_property_info);
     383             :         }
     384       36499 :         return property_info;
     385             : }
     386             : /* }}} */
     387             : 
     388         138 : ZEND_API struct _zend_property_info *zend_get_property_info(zend_class_entry *ce, zend_string *member, int silent TSRMLS_DC) /* {{{ */
     389             : {
     390         138 :         return zend_get_property_info_quick(ce, member, silent, NULL TSRMLS_CC);
     391             : }
     392             : /* }}} */
     393             : 
     394         828 : ZEND_API int zend_check_property_access(zend_object *zobj, zend_string *prop_info_name TSRMLS_DC) /* {{{ */
     395             : {
     396             :         zend_property_info *property_info;
     397         828 :         const char *class_name = NULL;
     398             :         const char *prop_name;
     399             :         zend_string *member;
     400             :         size_t prop_name_len;
     401             : 
     402         828 :         if (prop_info_name->val[0] == 0) {
     403         309 :                 zend_unmangle_property_name_ex(prop_info_name, &class_name, &prop_name, &prop_name_len);
     404         618 :                 member = zend_string_init(prop_name, prop_name_len, 0);
     405             :         } else {
     406         519 :                 member = zend_string_copy(prop_info_name);
     407             :         }
     408        1656 :         property_info = zend_get_property_info_quick(zobj->ce, member, 1, NULL TSRMLS_CC);
     409             :         zend_string_release(member);
     410         828 :         if (!property_info) {
     411          72 :                 return FAILURE;
     412             :         }
     413         756 :         if (class_name && class_name[0] != '*') {
     414         111 :                 if (!(property_info->flags & ZEND_ACC_PRIVATE)) {
     415             :                         /* we we're looking for a private prop but found a non private one of the same name */
     416          17 :                         return FAILURE;
     417          94 :                 } else if (strcmp(prop_info_name->val+1, property_info->name->val+1)) {
     418             :                         /* we we're looking for a private prop but found a private one of the same name but another class */
     419          11 :                         return FAILURE;
     420             :                 }
     421             :         }
     422        1456 :         return zend_verify_property_access(property_info, zobj->ce TSRMLS_CC) ? SUCCESS : FAILURE;
     423             : }
     424             : /* }}} */
     425             : 
     426         343 : static zend_long *zend_get_property_guard(zend_object *zobj, zend_property_info *property_info, zval *member) /* {{{ */
     427             : {
     428             :         zend_property_info info;
     429             :         zval stub, *guard;
     430         343 :         zend_string *str = NULL;
     431             : 
     432         343 :         if (!property_info) {
     433          50 :                 property_info = &info;
     434          50 :                 info.name = Z_STR_P(member);
     435         293 :         } else if(property_info->name->val[0] == '\0'){
     436          20 :                 const char *class_name = NULL, *prop_name = NULL;
     437             :                 size_t prop_name_len;
     438          20 :                 zend_unmangle_property_name_ex(property_info->name, &class_name,
     439             :                         &prop_name, &prop_name_len);
     440          20 :                 if (class_name) {
     441             :                         /* use unmangled name for protected properties */
     442          40 :                         str = info.name = zend_string_init(prop_name, prop_name_len, 0);
     443          20 :                         property_info = &info;
     444             :                 }
     445             :         }
     446         343 :         if (!zobj->guards) {
     447          70 :                 ALLOC_HASHTABLE(zobj->guards);
     448          70 :                 zend_hash_init(zobj->guards, 8, NULL, NULL, 0);
     449         273 :         } else if ((guard = zend_hash_find(zobj->guards, property_info->name)) != NULL) {
     450         221 :                 if (str) {
     451             :                         zend_string_release(str);
     452             :                 }
     453         221 :                 return &Z_LVAL_P(guard);
     454             :         }
     455             : 
     456         122 :         ZVAL_LONG(&stub, 0);
     457         122 :         guard = zend_hash_add_new(zobj->guards, property_info->name, &stub);
     458         122 :         if (str) {
     459             :                 zend_string_release(str);
     460             :         }
     461         122 :         return &Z_LVAL_P(guard);
     462             : }
     463             : /* }}} */
     464             : 
     465       36102 : zval *zend_std_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv TSRMLS_DC) /* {{{ */
     466             : {
     467             :         zend_object *zobj;
     468             :         zval tmp_member;
     469             :         zval *retval;
     470             :         zend_property_info *property_info;
     471             :         int silent;
     472             : 
     473       36102 :         silent = (type == BP_VAR_IS);
     474       36102 :         zobj = Z_OBJ_P(object);
     475             : 
     476       36102 :         ZVAL_UNDEF(&tmp_member);
     477       36102 :         if (UNEXPECTED(Z_TYPE_P(member) != IS_STRING)) {
     478           7 :                 ZVAL_DUP(&tmp_member, member);
     479           7 :                 convert_to_string(&tmp_member);
     480           7 :                 member = &tmp_member;
     481           7 :                 cache_slot = NULL;
     482             :         }
     483             : 
     484             : #if DEBUG_OBJECT_HANDLERS
     485             :         fprintf(stderr, "Read object #%d property: %s\n", Z_OBJ_HANDLE_P(object), Z_STRVAL_P(member));
     486             : #endif
     487             : 
     488             :         /* make zend_get_property_info silent if we have getter - we may want to use it */
     489       72200 :         property_info = zend_get_property_info_quick(zobj->ce, Z_STR_P(member), silent || (zobj->ce->__get != NULL), cache_slot TSRMLS_CC);
     490             : 
     491       36098 :         if (EXPECTED(property_info != NULL)) {
     492       72170 :                 if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
     493       36072 :                     property_info->offset >= 0) {
     494       34020 :                         retval = &zobj->properties_table[property_info->offset];
     495       34020 :                         if (Z_TYPE_P(retval) != IS_UNDEF) {
     496       34000 :                                 goto exit;
     497             :                         }
     498        2058 :                 } else if (UNEXPECTED(zobj->properties != NULL)) {
     499        1808 :                         retval = zend_hash_find(zobj->properties, property_info->name);
     500        1808 :                         if (retval) goto exit;
     501             :                 }
     502             :         }
     503             : 
     504             :         /* magic get */
     505         398 :         if (zobj->ce->__get) {
     506         144 :                 zend_long *guard = zend_get_property_guard(zobj, property_info, member);
     507         144 :                 if (!((*guard) & IN_GET)) {
     508             :                         zval tmp_object;
     509             : 
     510             :                         /* have getter - try with it! */
     511         134 :                         ZVAL_COPY(&tmp_object, object);
     512         134 :                         *guard |= IN_GET; /* prevent circular getting */
     513         134 :                         zend_std_call_getter(&tmp_object, member, rv TSRMLS_CC);
     514         133 :                         *guard &= ~IN_GET;
     515             : 
     516         133 :                         if (Z_TYPE_P(rv) != IS_UNDEF) {
     517         131 :                                 retval = rv;
     518         131 :                                 if (!Z_ISREF_P(rv) &&
     519             :                                     (type == BP_VAR_W || type == BP_VAR_RW  || type == BP_VAR_UNSET)) {
     520          37 :                                         SEPARATE_ZVAL(rv);
     521          19 :                                         if (UNEXPECTED(Z_TYPE_P(rv) != IS_OBJECT)) {
     522          13 :                                                 zend_error(E_NOTICE, "Indirect modification of overloaded property %s::$%s has no effect", zobj->ce->name->val, Z_STRVAL_P(member));
     523             :                                         }
     524             :                                 }
     525             :                         } else {
     526           2 :                                 retval = &EG(uninitialized_zval);
     527             :                         }
     528         133 :                         zval_ptr_dtor(&tmp_object);
     529             :                 } else {
     530          10 :                         if (Z_STRVAL_P(member)[0] == '\0') {
     531           1 :                                 if (Z_STRLEN_P(member) == 0) {
     532           1 :                                         zend_error(E_ERROR, "Cannot access empty property");
     533             :                                 } else {
     534           0 :                                         zend_error(E_ERROR, "Cannot access property started with '\\0'");
     535             :                                 }
     536             :                         }
     537           9 :                         if (!silent) {
     538           9 :                                 zend_error(E_NOTICE,"Undefined property: %s::$%s", zobj->ce->name->val, Z_STRVAL_P(member));
     539             :                         }
     540           9 :                         retval = &EG(uninitialized_zval);
     541             :                 }
     542             :         } else {
     543         254 :                 if (!silent) {
     544          40 :                         zend_error(E_NOTICE,"Undefined property: %s::$%s", zobj->ce->name->val, Z_STRVAL_P(member));
     545             :                 }
     546         254 :                 retval = &EG(uninitialized_zval);
     547             :         }
     548             : 
     549             : exit:
     550       36096 :         if (UNEXPECTED(Z_TYPE(tmp_member) != IS_UNDEF)) {
     551           6 :                 if (Z_REFCOUNTED_P(retval)) Z_ADDREF_P(retval);
     552           6 :                 zval_ptr_dtor(&tmp_member);
     553           6 :                 if (Z_REFCOUNTED_P(retval)) Z_DELREF_P(retval);
     554             :         }
     555       36096 :         return retval;
     556             : }
     557             : /* }}} */
     558             : 
     559      149519 : ZEND_API void zend_std_write_property(zval *object, zval *member, zval *value, void **cache_slot TSRMLS_DC) /* {{{ */
     560             : {
     561             :         zend_object *zobj;
     562             :         zval tmp_member;
     563             :         zval *variable_ptr;
     564             :         zend_property_info *property_info;
     565             : 
     566      149519 :         zobj = Z_OBJ_P(object);
     567             : 
     568      149519 :         ZVAL_UNDEF(&tmp_member);
     569      149519 :         if (UNEXPECTED(Z_TYPE_P(member) != IS_STRING)) {
     570           7 :                 ZVAL_DUP(&tmp_member, member);
     571           7 :                 convert_to_string(&tmp_member);
     572           7 :                 member = &tmp_member;
     573           7 :                 cache_slot = NULL;
     574             :         }
     575             : 
     576      299028 :         property_info = zend_get_property_info_quick(zobj->ce, Z_STR_P(member), (zobj->ce->__set != NULL), cache_slot TSRMLS_CC);
     577             : 
     578      149509 :         if (EXPECTED(property_info != NULL)) {
     579      298995 :                 if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
     580      149483 :                     property_info->offset >= 0) {
     581      104813 :                         variable_ptr = &zobj->properties_table[property_info->offset];
     582      104813 :                         if (Z_TYPE_P(variable_ptr) != IS_UNDEF) {
     583      104793 :                                 goto found;
     584             :                         }
     585       44679 :                 } else if (EXPECTED(zobj->properties != NULL)) {
     586       30867 :                         if ((variable_ptr = zend_hash_find(zobj->properties, property_info->name)) != NULL) {
     587             : found:
     588             :                                 /* if we already have this value there, we don't actually need to do anything */
     589      105017 :                                 if (EXPECTED(variable_ptr != value)) {
     590             :                                         /* if we are assigning reference, we shouldn't move it, but instead assign variable
     591             :                                            to the same pointer */
     592      105016 :                                         if (Z_ISREF_P(variable_ptr)) {
     593             :                                                 zval garbage;
     594             : 
     595          38 :                                                 ZVAL_COPY_VALUE(&garbage, Z_REFVAL_P(variable_ptr)); /* old value should be destroyed */
     596             : 
     597             :                                                 /* To check: can't *variable_ptr be some system variable like error_zval here? */
     598          38 :                                                 if (UNEXPECTED(Z_REFCOUNTED_P(value))) {
     599           0 :                                                         if (EXPECTED(!Z_ISREF_P(value))) {
     600             :                                                                 Z_ADDREF_P(value);
     601             :                                                         } else {
     602           0 :                                                                 if (Z_REFCOUNT_P(value) == 1) {
     603           0 :                                                                         ZVAL_UNREF(value);
     604             :                                                                 } else {
     605           0 :                                                                         value = Z_REFVAL_P(value);
     606             :                                                                 }
     607           0 :                                                                 if (Z_REFCOUNTED_P(value)) {
     608           0 :                                                                         if (UNEXPECTED(Z_REFVAL_P(variable_ptr) == value)) {
     609           0 :                                                                                 goto exit;
     610             :                                                                         }
     611             :                                                                         Z_ADDREF_P(value);
     612             :                                                                 }
     613             :                                                         }
     614             :                                                 }
     615          38 :                                                 ZVAL_COPY_VALUE(Z_REFVAL_P(variable_ptr), value);
     616          38 :                                                 zval_ptr_dtor(&garbage);
     617             :                                         } else {
     618             :                                                 zval garbage;
     619             : 
     620      104978 :                                                 ZVAL_COPY_VALUE(&garbage, variable_ptr);
     621             : 
     622             :                                                 /* if we assign referenced variable, we should separate it */
     623      104978 :                                                 ZVAL_COPY_VALUE(variable_ptr, value);
     624      104978 :                                                 if (Z_REFCOUNTED_P(variable_ptr)) {
     625             :                                                         Z_ADDREF_P(variable_ptr);
     626        9185 :                                                         if (Z_ISREF_P(variable_ptr)) {
     627          24 :                                                                 SEPARATE_ZVAL(variable_ptr);
     628             :                                                         }
     629             :                                                 }
     630      104978 :                                                 zval_ptr_dtor(&garbage);
     631             :                                         }
     632             :                                 }
     633      105017 :                                 goto exit;
     634             :                         }
     635             :                 }
     636             :         }
     637             : 
     638             :         /* magic set */
     639       44492 :         if (zobj->ce->__set) {
     640         121 :                 zend_long *guard = zend_get_property_guard(zobj, property_info, member);
     641             : 
     642         121 :             if (!((*guard) & IN_SET)) {
     643             :                         zval tmp_object;
     644             : 
     645         100 :                         ZVAL_COPY(&tmp_object, object);
     646         100 :                         (*guard) |= IN_SET; /* prevent circular setting */
     647         100 :                         if (zend_std_call_setter(&tmp_object, member, value TSRMLS_CC) != SUCCESS) {
     648             :                                 /* for now, just ignore it - __set should take care of warnings, etc. */
     649             :                         }
     650          99 :                         (*guard) &= ~IN_SET;
     651          99 :                         zval_ptr_dtor(&tmp_object);
     652          21 :                 } else if (EXPECTED(property_info != NULL)) {
     653          19 :                         goto write_std_property;
     654             :                 } else {
     655           2 :                         if (Z_STRVAL_P(member)[0] == '\0') {
     656           1 :                                 if (Z_STRLEN_P(member) == 0) {
     657           1 :                                         zend_error(E_ERROR, "Cannot access empty property");
     658             :                                 } else {
     659           0 :                                         zend_error(E_ERROR, "Cannot access property started with '\\0'");
     660             :                                 }
     661             :                         }
     662             :                 }
     663       44371 :         } else if (EXPECTED(property_info != NULL)) {
     664             :                 zval tmp;
     665             : 
     666             : write_std_property:
     667       44390 :                 if (Z_REFCOUNTED_P(value)) {
     668       23572 :                         if (Z_ISREF_P(value)) {
     669             :                                 /* if we assign referenced variable, we should separate it */
     670       10009 :                                 ZVAL_DUP(&tmp, Z_REFVAL_P(value));
     671       10009 :                                 value = &tmp;
     672             :                         } else {
     673             :                                 Z_ADDREF_P(value);
     674             :                         }
     675             :                 }
     676       88789 :                 if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
     677       44385 :                     property_info->offset >= 0) {
     678             : 
     679          14 :                         ZVAL_COPY_VALUE(&zobj->properties_table[property_info->offset], value);
     680             :                 } else {
     681       44376 :                         if (!zobj->properties) {
     682       13736 :                                 rebuild_object_properties(zobj);
     683             :                         }
     684       44376 :                         zend_hash_update(zobj->properties, property_info->name, value);
     685             :                 }
     686             :         }
     687             : 
     688             : exit:
     689      149507 :         if (UNEXPECTED(Z_TYPE(tmp_member) != IS_UNDEF)) {
     690           6 :                 zval_ptr_dtor(&tmp_member);
     691             :         }
     692      149507 : }
     693             : /* }}} */
     694             : 
     695         482 : zval *zend_std_read_dimension(zval *object, zval *offset, int type, zval *rv TSRMLS_DC) /* {{{ */
     696             : {
     697         482 :         zend_class_entry *ce = Z_OBJCE_P(object);
     698             :         zval tmp;
     699             : 
     700         482 :         if (EXPECTED(instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC) != 0)) {
     701         478 :                 if(offset == NULL) {
     702             :                         /* [] construct */
     703           0 :                         ZVAL_UNDEF(&tmp);
     704           0 :                         offset = &tmp;
     705             :                 } else {
     706         478 :                         SEPARATE_ARG_IF_REF(offset);
     707             :                 }
     708         478 :                 zend_call_method_with_1_params(object, ce, NULL, "offsetget", rv, offset);
     709             : 
     710         478 :                 zval_ptr_dtor(offset);
     711             : 
     712         478 :                 if (UNEXPECTED(Z_TYPE_P(rv) == IS_UNDEF)) {
     713           5 :                         if (UNEXPECTED(!EG(exception))) {
     714           0 :                                 zend_error_noreturn(E_ERROR, "Undefined offset for object of type %s used as array", ce->name->val);
     715             :                         }
     716           5 :                         return NULL;
     717             :                 }
     718         473 :                 return rv;
     719             :         } else {
     720           4 :                 zend_error_noreturn(E_ERROR, "Cannot use object of type %s as array", ce->name->val);
     721             :                 return NULL;
     722             :         }
     723             : }
     724             : /* }}} */
     725             : 
     726        1324 : static void zend_std_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) /* {{{ */
     727             : {
     728        1324 :         zend_class_entry *ce = Z_OBJCE_P(object);
     729             :         zval tmp;
     730             : 
     731        1324 :         if (EXPECTED(instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC) != 0)) {
     732        1323 :                 if (!offset) {
     733          10 :                         ZVAL_NULL(&tmp);
     734          10 :                         offset = &tmp;
     735             :                 } else {
     736        1313 :                         SEPARATE_ARG_IF_REF(offset);
     737             :                 }
     738        1323 :                 zend_call_method_with_2_params(object, ce, NULL, "offsetset", NULL, offset, value);
     739        1323 :                 zval_ptr_dtor(offset);
     740             :         } else {
     741           1 :                 zend_error_noreturn(E_ERROR, "Cannot use object of type %s as array", ce->name->val);
     742             :         }
     743        1323 : }
     744             : /* }}} */
     745             : 
     746        1078 : static int zend_std_has_dimension(zval *object, zval *offset, int check_empty TSRMLS_DC) /* {{{ */
     747             : {
     748        1078 :         zend_class_entry *ce = Z_OBJCE_P(object);
     749             :         zval retval;
     750             :         int result;
     751             : 
     752        1078 :         if (EXPECTED(instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC) != 0)) {
     753        1078 :                 SEPARATE_ARG_IF_REF(offset);
     754        1078 :                 zend_call_method_with_1_params(object, ce, NULL, "offsetexists", &retval, offset);
     755        1078 :                 if (EXPECTED(Z_TYPE(retval) != IS_UNDEF)) {
     756        1076 :                         result = i_zend_is_true(&retval TSRMLS_CC);
     757        1076 :                         zval_ptr_dtor(&retval);
     758        1076 :                         if (check_empty && result && EXPECTED(!EG(exception))) {
     759           8 :                                 zend_call_method_with_1_params(object, ce, NULL, "offsetget", &retval, offset);
     760           8 :                                 if (EXPECTED(Z_TYPE(retval) != IS_UNDEF)) {
     761           8 :                                         result = i_zend_is_true(&retval TSRMLS_CC);
     762           8 :                                         zval_ptr_dtor(&retval);
     763             :                                 }
     764             :                         }
     765             :                 } else {
     766           2 :                         result = 0;
     767             :                 }
     768        1078 :                 zval_ptr_dtor(offset);
     769             :         } else {
     770           0 :                 zend_error_noreturn(E_ERROR, "Cannot use object of type %s as array", ce->name->val);
     771             :                 return 0;
     772             :         }
     773        1078 :         return result;
     774             : }
     775             : /* }}} */
     776             : 
     777      179760 : static zval *zend_std_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot TSRMLS_DC) /* {{{ */
     778             : {
     779             :         zend_object *zobj;
     780             :         zval tmp_member;
     781             :         zval *retval, tmp;
     782             :         zend_property_info *property_info;
     783             :         zend_long *guard;
     784             : 
     785      179760 :         zobj = Z_OBJ_P(object);
     786             : 
     787      179760 :         ZVAL_UNDEF(&tmp_member);
     788      179760 :         if (UNEXPECTED(Z_TYPE_P(member) != IS_STRING)) {
     789           0 :                 ZVAL_DUP(&tmp_member, member);
     790           0 :                 convert_to_string(&tmp_member);
     791           0 :                 member = &tmp_member;
     792           0 :                 cache_slot = NULL;
     793             :         }
     794             : 
     795             : #if DEBUG_OBJECT_HANDLERS
     796             :         fprintf(stderr, "Ptr object #%d property: %s\n", Z_OBJ_HANDLE_P(object), Z_STRVAL_P(member));
     797             : #endif
     798             : 
     799      359517 :         property_info = zend_get_property_info_quick(zobj->ce, Z_STR_P(member), (zobj->ce->__get != NULL), cache_slot TSRMLS_CC);
     800             : 
     801      179757 :         if (EXPECTED(property_info != NULL)) {
     802      359505 :                 if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
     803      179752 :                     property_info->offset >= 0) {
     804      179500 :                         retval = &zobj->properties_table[property_info->offset];
     805      179500 :                         if (Z_TYPE_P(retval) != IS_UNDEF) {
     806      179500 :                                 goto exit;
     807             :                         }
     808         253 :                 } else if (UNEXPECTED(zobj->properties != NULL)) {
     809         151 :                         retval = zend_hash_find(zobj->properties, property_info->name);
     810         151 :                         if (retval) goto exit;
     811             :                 }
     812             :         }
     813             : 
     814         330 :         if (!zobj->ce->__get ||
     815          38 :                 (guard = zend_get_property_guard(zobj, property_info, member)) == NULL ||
     816          34 :                 (property_info && ((*guard) & IN_GET))) {
     817             : 
     818             :                 /* we don't have access controls - will just add it */
     819         110 :                 if(UNEXPECTED(type == BP_VAR_RW || type == BP_VAR_R)) {
     820          14 :                         zend_error(E_NOTICE, "Undefined property: %s::$%s", zobj->ce->name->val, Z_STRVAL_P(member));
     821             :                 }
     822         110 :                 ZVAL_NULL(&tmp);
     823         220 :                 if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
     824         110 :                     property_info->offset >= 0) {
     825           0 :                         retval = &zobj->properties_table[property_info->offset];
     826           0 :                         ZVAL_NULL(retval);
     827             :                 } else {
     828         110 :                         if (!zobj->properties) {
     829          69 :                                 rebuild_object_properties(zobj);
     830             :                         }
     831         110 :                         retval = zend_hash_update(zobj->properties, property_info->name, &tmp);
     832             :                 }
     833             :         } else {
     834             :                 /* we do have getter - fail and let it try again with usual get/set */
     835          38 :                 retval = NULL;
     836             :         }
     837             : 
     838             : exit:
     839      179757 :         if (UNEXPECTED(Z_TYPE(tmp_member) != IS_UNDEF)) {
     840             :                 zval_dtor(&tmp_member);
     841             :         }
     842      179757 :         return retval;
     843             : }
     844             : /* }}} */
     845             : 
     846         157 : static void zend_std_unset_property(zval *object, zval *member, void **cache_slot TSRMLS_DC) /* {{{ */
     847             : {
     848             :         zend_object *zobj;
     849             :         zval tmp_member;
     850             :         zend_property_info *property_info;
     851             : 
     852         157 :         zobj = Z_OBJ_P(object);
     853             : 
     854         157 :         ZVAL_UNDEF(&tmp_member);
     855         157 :         if (UNEXPECTED(Z_TYPE_P(member) != IS_STRING)) {
     856           1 :                 ZVAL_DUP(&tmp_member, member);
     857           1 :                 convert_to_string(&tmp_member);
     858           1 :                 member = &tmp_member;
     859           1 :                 cache_slot = NULL;
     860             :         }
     861             : 
     862         313 :         property_info = zend_get_property_info_quick(zobj->ce, Z_STR_P(member), (zobj->ce->__unset != NULL), cache_slot TSRMLS_CC);
     863             : 
     864         156 :         if (EXPECTED(property_info != NULL)) {
     865         307 :                 if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
     866         153 :                     property_info->offset >= 0) {
     867         104 :                         if (Z_TYPE(zobj->properties_table[property_info->offset]) != IS_UNDEF) {
     868          52 :                                 zval_ptr_dtor(&zobj->properties_table[property_info->offset]);
     869          52 :                                 ZVAL_UNDEF(&zobj->properties_table[property_info->offset]);
     870          52 :                                 goto exit;
     871             :                         }
     872         196 :                 } else if (zobj->properties &&
     873          94 :                 UNEXPECTED(zend_hash_del(zobj->properties, property_info->name) != FAILURE)) {
     874          87 :                         goto exit;
     875             :                 }
     876             :         }
     877             :         
     878             :         /* magic unset */
     879          17 :         if (zobj->ce->__unset) {
     880           9 :                 zend_long *guard = zend_get_property_guard(zobj, property_info, member);
     881           9 :                 if (!((*guard) & IN_UNSET)) {
     882             :                         zval tmp_object;
     883             : 
     884             :                         /* have unseter - try with it! */
     885           8 :                         ZVAL_COPY(&tmp_object, object);
     886           8 :                         (*guard) |= IN_UNSET; /* prevent circular unsetting */
     887           8 :                         zend_std_call_unsetter(&tmp_object, member TSRMLS_CC);
     888           7 :                         (*guard) &= ~IN_UNSET;
     889           7 :                         zval_ptr_dtor(&tmp_object);
     890             :                 } else {
     891           1 :                         if (Z_STRVAL_P(member)[0] == '\0') {
     892           1 :                                 if (Z_STRLEN_P(member) == 0) {
     893           1 :                                         zend_error(E_ERROR, "Cannot access empty property");
     894             :                                 } else {
     895           0 :                                         zend_error(E_ERROR, "Cannot access property started with '\\0'");
     896             :                                 }
     897             :                         }
     898             :                 }
     899             :         }
     900             : 
     901             : exit:
     902         154 :         if (UNEXPECTED(Z_TYPE(tmp_member) != IS_NULL)) {
     903         154 :                 zval_ptr_dtor(&tmp_member);
     904             :         }
     905         154 : }
     906             : /* }}} */
     907             : 
     908          27 : static void zend_std_unset_dimension(zval *object, zval *offset TSRMLS_DC) /* {{{ */
     909             : {
     910          27 :         zend_class_entry *ce = Z_OBJCE_P(object);
     911             : 
     912          27 :         if (instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC)) {
     913          27 :                 SEPARATE_ARG_IF_REF(offset);
     914          27 :                 zend_call_method_with_1_params(object, ce, NULL, "offsetunset", NULL, offset);
     915          27 :                 zval_ptr_dtor(offset);
     916             :         } else {
     917           0 :                 zend_error_noreturn(E_ERROR, "Cannot use object of type %s as array", ce->name->val);
     918             :         }
     919          27 : }
     920             : /* }}} */
     921             : 
     922         441 : ZEND_API void zend_std_call_user_call(INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
     923             : {
     924         441 :         zend_internal_function *func = (zend_internal_function *)EG(current_execute_data)->func;
     925             :         zval method_name, method_args;
     926             :         zval method_result;
     927         441 :         zend_class_entry *ce = Z_OBJCE_P(getThis());
     928             : 
     929         441 :         array_init_size(&method_args, ZEND_NUM_ARGS());
     930             : 
     931         441 :         if (UNEXPECTED(zend_copy_parameters_array(ZEND_NUM_ARGS(), &method_args TSRMLS_CC) == FAILURE)) {
     932             :                 zval_dtor(&method_args);
     933           0 :                 zend_error_noreturn(E_ERROR, "Cannot get arguments for __call");
     934             :                 RETURN_FALSE;
     935             :         }
     936             : 
     937         441 :         ZVAL_STR(&method_name, func->function_name); /* no dup - it's a copy */
     938             : 
     939             :         /* __call handler is called with two arguments:
     940             :            method name
     941             :            array of method parameters
     942             : 
     943             :         */
     944         441 :         zend_call_method_with_2_params(getThis(), ce, &ce->__call, ZEND_CALL_FUNC_NAME, &method_result, &method_name, &method_args);
     945             : 
     946         431 :         if (Z_TYPE(method_result) != IS_UNDEF) {
     947        1254 :                 RETVAL_ZVAL_FAST(&method_result);
     948         418 :                 zval_ptr_dtor(&method_result);
     949             :         }
     950             : 
     951             :         /* now destruct all auxiliaries */
     952         431 :         zval_ptr_dtor(&method_args);
     953         431 :         zval_ptr_dtor(&method_name);
     954             : 
     955             :         /* destruct the function also, then - we have allocated it in get_method */
     956         431 :         efree_size(func, sizeof(zend_internal_function));
     957             : }
     958             : /* }}} */
     959             : 
     960             : /* Ensures that we're allowed to call a private method.
     961             :  * Returns the function address that should be called, or NULL
     962             :  * if no such function exists.
     963             :  */
     964         180 : static inline zend_function *zend_check_private_int(zend_function *fbc, zend_class_entry *ce, zend_string *function_name TSRMLS_DC) /* {{{ */
     965             : {
     966             :     zval *func;
     967             : 
     968         180 :         if (!ce) {
     969           7 :                 return 0;
     970             :         }
     971             : 
     972             :         /* We may call a private function if:
     973             :          * 1.  The class of our object is the same as the scope, and the private
     974             :          *     function (EX(fbc)) has the same scope.
     975             :          * 2.  One of our parent classes are the same as the scope, and it contains
     976             :          *     a private function with the same name that has the same scope.
     977             :          */
     978         173 :         if (fbc->common.scope == ce && EG(scope) == ce) {
     979             :                 /* rule #1 checks out ok, allow the function call */
     980         131 :                 return fbc;
     981             :         }
     982             : 
     983             : 
     984             :         /* Check rule #2 */
     985          42 :         ce = ce->parent;
     986          96 :         while (ce) {
     987          23 :                 if (ce == EG(scope)) {
     988          11 :                         if ((func = zend_hash_find(&ce->function_table, function_name))) {
     989          11 :                                 fbc = Z_FUNC_P(func);
     990          22 :                                 if (fbc->common.fn_flags & ZEND_ACC_PRIVATE
     991          22 :                                         && fbc->common.scope == EG(scope)) {
     992           9 :                                         return fbc;
     993             :                                 }
     994             :                         }
     995           2 :                         break;
     996             :                 }
     997          12 :                 ce = ce->parent;
     998             :         }
     999          33 :         return NULL;
    1000             : }
    1001             : /* }}} */
    1002             : 
    1003          32 : ZEND_API int zend_check_private(zend_function *fbc, zend_class_entry *ce, zend_string *function_name TSRMLS_DC) /* {{{ */
    1004             : {
    1005          32 :         return zend_check_private_int(fbc, ce, function_name TSRMLS_CC) != NULL;
    1006             : }
    1007             : /* }}} */
    1008             : 
    1009             : /* Ensures that we're allowed to call a protected method.
    1010             :  */
    1011        7677 : ZEND_API int zend_check_protected(zend_class_entry *ce, zend_class_entry *scope) /* {{{ */
    1012             : {
    1013        7677 :         zend_class_entry *fbc_scope = ce;
    1014             : 
    1015             :         /* Is the context that's calling the function, the same as one of
    1016             :          * the function's parents?
    1017             :          */
    1018       15891 :         while (fbc_scope) {
    1019        7919 :                 if (fbc_scope==scope) {
    1020        7382 :                         return 1;
    1021             :                 }
    1022         537 :                 fbc_scope = fbc_scope->parent;
    1023             :         }
    1024             : 
    1025             :         /* Is the function's scope the same as our current object context,
    1026             :          * or any of the parents of our context?
    1027             :          */
    1028         803 :         while (scope) {
    1029         382 :                 if (scope==ce) {
    1030         169 :                         return 1;
    1031             :                 }
    1032         213 :                 scope = scope->parent;
    1033             :         }
    1034         126 :         return 0;
    1035             : }
    1036             : /* }}} */
    1037             : 
    1038         441 : static inline union _zend_function *zend_get_user_call_function(zend_class_entry *ce, zend_string *method_name) /* {{{ */
    1039             : {
    1040         441 :         zend_internal_function *call_user_call = emalloc(sizeof(zend_internal_function));
    1041         441 :         call_user_call->type = ZEND_INTERNAL_FUNCTION;
    1042         441 :         call_user_call->module = (ce->type == ZEND_INTERNAL_CLASS) ? ce->info.internal.module : NULL;
    1043         441 :         call_user_call->handler = zend_std_call_user_call;
    1044         441 :         call_user_call->arg_info = NULL;
    1045         441 :         call_user_call->num_args = 0;
    1046         441 :         call_user_call->scope = ce;
    1047         441 :         call_user_call->fn_flags = ZEND_ACC_CALL_VIA_HANDLER;
    1048             :         //??? keep compatibility for "\0" characters
    1049             :         //??? see: Zend/tests/bug46238.phpt
    1050         441 :         if (UNEXPECTED(strlen(method_name->val) != method_name->len)) {
    1051           0 :                 call_user_call->function_name = zend_string_init(method_name->val, strlen(method_name->val), 0);
    1052             :         } else {
    1053         441 :                 call_user_call->function_name = zend_string_copy(method_name);
    1054             :         }
    1055             : 
    1056         441 :         return (union _zend_function *)call_user_call;
    1057             : }
    1058             : /* }}} */
    1059             : 
    1060       21978 : static union _zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *method_name, const zval *key TSRMLS_DC) /* {{{ */
    1061             : {
    1062       21978 :         zend_object *zobj = *obj_ptr;
    1063             :         zval *func;
    1064             :         zend_function *fbc;
    1065             :         zend_string *lc_method_name;
    1066             :         ALLOCA_FLAG(use_heap);
    1067             : 
    1068       21978 :         if (EXPECTED(key != NULL)) {
    1069       21522 :                 lc_method_name = Z_STR_P(key);
    1070             :         } else {
    1071         456 :                 STR_ALLOCA_ALLOC(lc_method_name, method_name->len, use_heap);
    1072         456 :                 zend_str_tolower_copy(lc_method_name->val, method_name->val, method_name->len);
    1073             :         }
    1074             : 
    1075       21978 :         if (UNEXPECTED((func = zend_hash_find(&zobj->ce->function_table, lc_method_name)) == NULL)) {
    1076        1807 :                 if (UNEXPECTED(!key)) {
    1077         301 :                         STR_ALLOCA_FREE(lc_method_name, use_heap);
    1078             :                 }
    1079        1807 :                 if (zobj->ce->__call) {
    1080         396 :                         return zend_get_user_call_function(zobj->ce, method_name);
    1081             :                 } else {
    1082        1411 :                         return NULL;
    1083             :                 }
    1084             :         }
    1085             : 
    1086       20171 :         fbc = Z_FUNC_P(func);
    1087             :         /* Check access level */
    1088       20171 :         if (fbc->op_array.fn_flags & ZEND_ACC_PRIVATE) {
    1089             :                 zend_function *updated_fbc;
    1090             : 
    1091             :                 /* Ensure that if we're calling a private function, we're allowed to do so.
    1092             :                  * If we're not and __call() handler exists, invoke it, otherwise error out.
    1093             :                  */
    1094         131 :                 updated_fbc = zend_check_private_int(fbc, zobj->handlers->get_class_entry(zobj TSRMLS_CC), lc_method_name TSRMLS_CC);
    1095         131 :                 if (EXPECTED(updated_fbc != NULL)) {
    1096         120 :                         fbc = updated_fbc;
    1097             :                 } else {
    1098          11 :                         if (zobj->ce->__call) {
    1099           3 :                                 fbc = zend_get_user_call_function(zobj->ce, method_name);
    1100             :                         } else {
    1101           8 :                                 zend_error_noreturn(E_ERROR, "Call to %s method %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), method_name->val, EG(scope) ? EG(scope)->name->val : "");
    1102             :                         }
    1103             :                 }
    1104             :         } else {
    1105             :                 /* Ensure that we haven't overridden a private function and end up calling
    1106             :                  * the overriding public function...
    1107             :                  */
    1108       23887 :                 if (EG(scope) &&
    1109        3837 :                     is_derived_class(fbc->common.scope, EG(scope)) &&
    1110          10 :                     fbc->op_array.fn_flags & ZEND_ACC_CHANGED) {
    1111           7 :                         if ((func = zend_hash_find(&EG(scope)->function_table, lc_method_name)) != NULL) {
    1112           7 :                                 zend_function *priv_fbc = Z_FUNC_P(func);
    1113          14 :                                 if (priv_fbc->common.fn_flags & ZEND_ACC_PRIVATE
    1114          14 :                                         && priv_fbc->common.scope == EG(scope)) {
    1115           6 :                                         fbc = priv_fbc;
    1116             :                                 }
    1117             :                         }
    1118             :                 }
    1119       20040 :                 if ((fbc->common.fn_flags & ZEND_ACC_PROTECTED)) {
    1120             :                         /* Ensure that if we're calling a protected function, we're allowed to do so.
    1121             :                          * If we're not and __call() handler exists, invoke it, otherwise error out.
    1122             :                          */
    1123          32 :                         if (UNEXPECTED(!zend_check_protected(zend_get_function_root_class(fbc), EG(scope)))) {
    1124          12 :                                 if (zobj->ce->__call) {
    1125           3 :                                         fbc = zend_get_user_call_function(zobj->ce, method_name);
    1126             :                                 } else {
    1127           9 :                                         zend_error_noreturn(E_ERROR, "Call to %s method %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), method_name->val, EG(scope) ? EG(scope)->name->val : "");
    1128             :                                 }
    1129             :                         }
    1130             :                 }
    1131             :         }
    1132             : 
    1133       20154 :         if (UNEXPECTED(!key)) {
    1134         155 :                 STR_ALLOCA_FREE(lc_method_name, use_heap);
    1135             :         }
    1136       20154 :         return fbc;
    1137             : }
    1138             : /* }}} */
    1139             : 
    1140          49 : ZEND_API void zend_std_callstatic_user_call(INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
    1141             : {
    1142          49 :         zend_internal_function *func = (zend_internal_function *)EG(current_execute_data)->func;
    1143             :         zval method_name, method_args;
    1144             :         zval method_result;
    1145          49 :         zend_class_entry *ce = EG(scope);
    1146             : 
    1147          49 :         array_init_size(&method_args, ZEND_NUM_ARGS());
    1148             : 
    1149          49 :         if (UNEXPECTED(zend_copy_parameters_array(ZEND_NUM_ARGS(), &method_args TSRMLS_CC) == FAILURE)) {
    1150             :                 zval_dtor(&method_args);
    1151           0 :                 zend_error_noreturn(E_ERROR, "Cannot get arguments for " ZEND_CALLSTATIC_FUNC_NAME);
    1152             :                 RETURN_FALSE;
    1153             :         }
    1154             : 
    1155          49 :         ZVAL_STR(&method_name, func->function_name); /* no dup - it's a copy */
    1156             : 
    1157             :         /* __callStatic handler is called with two arguments:
    1158             :            method name
    1159             :            array of method parameters
    1160             :         */
    1161          49 :         zend_call_method_with_2_params(NULL, ce, &ce->__callstatic, ZEND_CALLSTATIC_FUNC_NAME, &method_result, &method_name, &method_args);
    1162             : 
    1163          49 :         if (Z_TYPE(method_result) != IS_UNDEF) {
    1164         141 :                 RETVAL_ZVAL_FAST(&method_result);
    1165          47 :                 zval_ptr_dtor(&method_result);
    1166             :         }
    1167             : 
    1168             :         /* now destruct all auxiliaries */
    1169          49 :         zval_ptr_dtor(&method_args);
    1170          49 :         zval_ptr_dtor(&method_name);
    1171             : 
    1172             :         /* destruct the function also, then - we have allocated it in get_method */
    1173          49 :         efree_size(func, sizeof(zend_internal_function));
    1174             : }
    1175             : /* }}} */
    1176             : 
    1177          49 : static inline union _zend_function *zend_get_user_callstatic_function(zend_class_entry *ce, zend_string *method_name) /* {{{ */
    1178             : {
    1179          49 :         zend_internal_function *callstatic_user_call = emalloc(sizeof(zend_internal_function));
    1180          49 :         callstatic_user_call->type     = ZEND_INTERNAL_FUNCTION;
    1181          49 :         callstatic_user_call->module   = (ce->type == ZEND_INTERNAL_CLASS) ? ce->info.internal.module : NULL;
    1182          49 :         callstatic_user_call->handler  = zend_std_callstatic_user_call;
    1183          49 :         callstatic_user_call->arg_info = NULL;
    1184          49 :         callstatic_user_call->num_args = 0;
    1185          49 :         callstatic_user_call->scope    = ce;
    1186          49 :         callstatic_user_call->fn_flags = ZEND_ACC_STATIC | ZEND_ACC_PUBLIC | ZEND_ACC_CALL_VIA_HANDLER;
    1187             :         //??? keep compatibility for "\0" characters
    1188             :         //??? see: Zend/tests/bug46238.phpt
    1189          49 :         if (UNEXPECTED(strlen(method_name->val) != method_name->len)) {
    1190          10 :                 callstatic_user_call->function_name = zend_string_init(method_name->val, strlen(method_name->val), 0);
    1191             :         } else {
    1192          44 :                 callstatic_user_call->function_name = zend_string_copy(method_name);
    1193             :         }
    1194             : 
    1195          49 :         return (zend_function *)callstatic_user_call;
    1196             : }
    1197             : /* }}} */
    1198             : 
    1199             : /* This is not (yet?) in the API, but it belongs in the built-in objects callbacks */
    1200             : 
    1201        3383 : ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, zend_string *function_name, const zval *key TSRMLS_DC) /* {{{ */
    1202             : {
    1203        3383 :         zend_function *fbc = NULL;
    1204             :         char *lc_class_name;
    1205             :         zend_string *lc_function_name;
    1206             : 
    1207        3383 :         if (EXPECTED(key != NULL)) {
    1208        3313 :                 lc_function_name = Z_STR_P(key);
    1209             :         } else {
    1210         140 :                 lc_function_name = zend_string_alloc(function_name->len, 0);
    1211          70 :                 zend_str_tolower_copy(lc_function_name->val, function_name->val, function_name->len);
    1212             :         }
    1213             : 
    1214        3383 :         if (function_name->len == ce->name->len && ce->constructor) {
    1215          52 :                 lc_class_name = zend_str_tolower_dup(ce->name->val, ce->name->len);
    1216             :                 /* Only change the method to the constructor if the constructor isn't called __construct
    1217             :                  * we check for __ so we can be binary safe for lowering, we should use ZEND_CONSTRUCTOR_FUNC_NAME
    1218             :                  */
    1219          52 :                 if (!memcmp(lc_class_name, lc_function_name->val, function_name->len) && memcmp(ce->constructor->common.function_name->val, "__", sizeof("__") - 1)) {
    1220           5 :                         fbc = ce->constructor;
    1221             :                 }
    1222          52 :                 efree(lc_class_name);
    1223             :         }
    1224             : 
    1225        3383 :         if (EXPECTED(!fbc)) {
    1226        3378 :                 zval *func = zend_hash_find(&ce->function_table, lc_function_name);
    1227        3378 :                 if (EXPECTED(func != NULL)) {
    1228        3273 :                         fbc = Z_FUNC_P(func);
    1229             :                 } else {
    1230         105 :                         if (UNEXPECTED(!key)) {
    1231             :                                 zend_string_free(lc_function_name);
    1232             :                         }
    1233         252 :                         if (ce->__call &&
    1234          67 :                             Z_OBJ(EG(This)) &&
    1235          40 :                             Z_OBJ_HT(EG(This))->get_class_entry &&
    1236          40 :                             instanceof_function(Z_OBJCE(EG(This)), ce TSRMLS_CC)) {
    1237          39 :                                 return zend_get_user_call_function(ce, function_name);
    1238          66 :                         } else if (ce->__callstatic) {
    1239          47 :                                 return zend_get_user_callstatic_function(ce, function_name);
    1240             :                         } else {
    1241          19 :                                 return NULL;
    1242             :                         }
    1243             :                 }
    1244             :         }
    1245             : 
    1246             : #if MBO_0
    1247             :         /* right now this function is used for non static method lookup too */
    1248             :         /* Is the function static */
    1249             :         if (UNEXPECTED(!(fbc->common.fn_flags & ZEND_ACC_STATIC))) {
    1250             :                 zend_error_noreturn(E_ERROR, "Cannot call non static method %s::%s() without object", ZEND_FN_SCOPE_NAME(fbc), fbc->common.function_name->val);
    1251             :         }
    1252             : #endif
    1253        3278 :         if (fbc->op_array.fn_flags & ZEND_ACC_PUBLIC) {
    1254             :                 /* No further checks necessary, most common case */
    1255          45 :         } else if (fbc->op_array.fn_flags & ZEND_ACC_PRIVATE) {
    1256             :                 zend_function *updated_fbc;
    1257             : 
    1258             :                 /* Ensure that if we're calling a private function, we're allowed to do so.
    1259             :                  */
    1260          17 :                 updated_fbc = zend_check_private_int(fbc, EG(scope), lc_function_name TSRMLS_CC);
    1261          17 :                 if (EXPECTED(updated_fbc != NULL)) {
    1262          10 :                         fbc = updated_fbc;
    1263             :                 } else {
    1264           7 :                         if (ce->__callstatic) {
    1265           1 :                                 fbc = zend_get_user_callstatic_function(ce, function_name);
    1266             :                         } else {
    1267           6 :                                 zend_error_noreturn(E_ERROR, "Call to %s method %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), function_name->val, EG(scope) ? EG(scope)->name->val : "");
    1268             :                         }
    1269             :                 }
    1270          28 :         } else if ((fbc->common.fn_flags & ZEND_ACC_PROTECTED)) {
    1271             :                 /* Ensure that if we're calling a protected function, we're allowed to do so.
    1272             :                  */
    1273          28 :                 if (UNEXPECTED(!zend_check_protected(zend_get_function_root_class(fbc), EG(scope)))) {
    1274           3 :                         if (ce->__callstatic) {
    1275           1 :                                 fbc = zend_get_user_callstatic_function(ce, function_name);
    1276             :                         } else {
    1277           2 :                                 zend_error_noreturn(E_ERROR, "Call to %s method %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), function_name->val, EG(scope) ? EG(scope)->name->val : "");
    1278             :                         }
    1279             :                 }
    1280             :         }
    1281             : 
    1282        3270 :         if (UNEXPECTED(!key)) {
    1283             :                 zend_string_free(lc_function_name);
    1284             :         }
    1285             : 
    1286        3270 :         return fbc;
    1287             : }
    1288             : /* }}} */
    1289             : 
    1290        1236 : ZEND_API zval *zend_std_get_static_property(zend_class_entry *ce, zend_string *property_name, zend_bool silent, void **cache_slot TSRMLS_DC) /* {{{ */
    1291             : {
    1292             :         zend_property_info *property_info;
    1293             : 
    1294        2443 :         if (UNEXPECTED(cache_slot == NULL) ||
    1295        1207 :             (property_info = CACHED_POLYMORPHIC_PTR_EX(cache_slot, ce)) == NULL) {
    1296             : 
    1297        1362 :                 if (UNEXPECTED((property_info = zend_hash_find_ptr(&ce->properties_info, property_name)) == NULL)) {
    1298          17 :                         if (!silent) {
    1299          10 :                                 zend_error_noreturn(E_ERROR, "Access to undeclared static property: %s::$%s", ce->name->val, property_name->val);
    1300             :                         }
    1301           7 :                         return NULL;
    1302             :                 }
    1303             : 
    1304         664 :                 if (UNEXPECTED(!zend_verify_property_access(property_info, ce TSRMLS_CC))) {
    1305          29 :                         if (!silent) {
    1306           2 :                                 zend_error_noreturn(E_ERROR, "Cannot access %s property %s::$%s", zend_visibility_string(property_info->flags), ce->name->val, property_name->val);
    1307             :                         }
    1308          27 :                         return NULL;
    1309             :                 }
    1310             : 
    1311         635 :                 if (UNEXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0)) {
    1312           0 :                         if (!silent) {
    1313           0 :                                 zend_error_noreturn(E_ERROR, "Access to undeclared static property: %s::$%s", ce->name->val, property_name->val);
    1314             :                         }
    1315           0 :                         return NULL;
    1316             :                 }
    1317             : 
    1318         635 :                 zend_update_class_constants(ce TSRMLS_CC);
    1319             : 
    1320         635 :                 if (EXPECTED(cache_slot != NULL)) {
    1321         619 :                         CACHE_POLYMORPHIC_PTR_EX(cache_slot, ce, property_info);
    1322             :                 }
    1323             :         }
    1324             : 
    1325        2380 :         if (UNEXPECTED(CE_STATIC_MEMBERS(ce) == NULL) ||
    1326        2380 :             UNEXPECTED(Z_TYPE(CE_STATIC_MEMBERS(ce)[property_info->offset]) == IS_UNDEF)) {
    1327           1 :                 if (!silent) {
    1328           1 :                         zend_error_noreturn(E_ERROR, "Access to undeclared static property: %s::$%s", ce->name->val, property_name->val);
    1329             :                 }
    1330           0 :                 return NULL;
    1331             :         }
    1332             :         
    1333        1189 :         return &CE_STATIC_MEMBERS(ce)[property_info->offset];
    1334             : }
    1335             : /* }}} */
    1336             : 
    1337           0 : ZEND_API zend_bool zend_std_unset_static_property(zend_class_entry *ce, zend_string *property_name, void **cache_slot TSRMLS_DC) /* {{{ */
    1338             : {
    1339           0 :         zend_error_noreturn(E_ERROR, "Attempt to unset static property %s::$%s", ce->name->val, property_name->val);
    1340             :         return 0;
    1341             : }
    1342             : /* }}} */
    1343             : 
    1344      461168 : ZEND_API union _zend_function *zend_std_get_constructor(zend_object *zobj TSRMLS_DC) /* {{{ */
    1345             : {
    1346      461168 :         zend_function *constructor = zobj->ce->constructor;
    1347             : 
    1348      461168 :         if (constructor) {
    1349      286762 :                 if (constructor->op_array.fn_flags & ZEND_ACC_PUBLIC) {
    1350             :                         /* No further checks necessary */
    1351          22 :                 } else if (constructor->op_array.fn_flags & ZEND_ACC_PRIVATE) {
    1352             :                         /* Ensure that if we're calling a private function, we're allowed to do so.
    1353             :                          */
    1354          14 :                         if (UNEXPECTED(constructor->common.scope != EG(scope))) {
    1355           5 :                                 if (EG(scope)) {
    1356           1 :                                         zend_error_noreturn(E_ERROR, "Call to private %s::%s() from context '%s'", constructor->common.scope->name->val, constructor->common.function_name->val, EG(scope)->name->val);
    1357             :                                 } else {
    1358           4 :                                         zend_error_noreturn(E_ERROR, "Call to private %s::%s() from invalid context", constructor->common.scope->name->val, constructor->common.function_name->val);
    1359             :                                 }
    1360             :                         }
    1361           8 :                 } else if ((constructor->common.fn_flags & ZEND_ACC_PROTECTED)) {
    1362             :                         /* Ensure that if we're calling a protected function, we're allowed to do so.
    1363             :                          * Constructors only have prototype if they are defined by an interface but
    1364             :                          * it is the compilers responsibility to take care of the prototype.
    1365             :                          */
    1366           8 :                         if (UNEXPECTED(!zend_check_protected(zend_get_function_root_class(constructor), EG(scope)))) {
    1367           2 :                                 if (EG(scope)) {
    1368           1 :                                         zend_error_noreturn(E_ERROR, "Call to protected %s::%s() from context '%s'", constructor->common.scope->name->val, constructor->common.function_name->val, EG(scope)->name->val);
    1369             :                                 } else {
    1370           1 :                                         zend_error_noreturn(E_ERROR, "Call to protected %s::%s() from invalid context", constructor->common.scope->name->val, constructor->common.function_name->val);
    1371             :                                 }
    1372             :                         }
    1373             :                 }
    1374             :         }
    1375             : 
    1376      461161 :         return constructor;
    1377             : }
    1378             : /* }}} */
    1379             : 
    1380             : int zend_compare_symbol_tables_i(HashTable *ht1, HashTable *ht2 TSRMLS_DC);
    1381             : 
    1382        1223 : static int zend_std_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
    1383             : {
    1384             :         zend_object *zobj1, *zobj2;
    1385             : 
    1386        1223 :         zobj1 = Z_OBJ_P(o1);
    1387        1223 :         zobj2 = Z_OBJ_P(o2);
    1388             : 
    1389        1223 :         if (zobj1->ce != zobj2->ce) {
    1390          34 :                 return 1; /* different classes */
    1391             :         }
    1392        1189 :         if (!zobj1->properties && !zobj2->properties) {
    1393             :                 int i;
    1394             : 
    1395         890 :                 Z_OBJ_PROTECT_RECURSION(o1);
    1396         889 :                 Z_OBJ_PROTECT_RECURSION(o2);
    1397         907 :                 for (i = 0; i < zobj1->ce->default_properties_count; i++) {
    1398        1768 :                         if (Z_TYPE(zobj1->properties_table[i]) != IS_UNDEF) {
    1399        1766 :                                 if (Z_TYPE(zobj2->properties_table[i]) != IS_UNDEF) {
    1400             :                                         zval result;
    1401         883 :                                         zval *p1 = &zobj1->properties_table[i];
    1402         883 :                                         zval *p2 = &zobj2->properties_table[i];
    1403             : 
    1404         883 :                                         if (compare_function(&result, p1, p2 TSRMLS_CC)==FAILURE) {
    1405           0 :                                                 Z_OBJ_UNPROTECT_RECURSION(o1);
    1406           0 :                                                 Z_OBJ_UNPROTECT_RECURSION(o2);
    1407           0 :                                                 return 1;
    1408             :                                         }
    1409         880 :                                         if (Z_LVAL(result) != 0) {
    1410         863 :                                                 Z_OBJ_UNPROTECT_RECURSION(o1);
    1411         863 :                                                 Z_OBJ_UNPROTECT_RECURSION(o2);
    1412         863 :                                                 return Z_LVAL(result);
    1413             :                                         }
    1414             :                                 } else {
    1415           0 :                                         Z_OBJ_UNPROTECT_RECURSION(o1);
    1416           0 :                                         Z_OBJ_UNPROTECT_RECURSION(o2);
    1417           0 :                                         return 1;
    1418             :                                 }
    1419             :                         } else {
    1420           2 :                                 if (Z_TYPE(zobj2->properties_table[i]) != IS_UNDEF) {
    1421           0 :                                         Z_OBJ_UNPROTECT_RECURSION(o1);
    1422           0 :                                         Z_OBJ_UNPROTECT_RECURSION(o2);
    1423           0 :                                         return 1;
    1424             :                                 }
    1425             :                         }
    1426             :                 }
    1427          23 :                 Z_OBJ_UNPROTECT_RECURSION(o1);
    1428          23 :                 Z_OBJ_UNPROTECT_RECURSION(o2);
    1429          23 :                 return 0;
    1430             :         } else {
    1431         299 :                 if (!zobj1->properties) {
    1432           1 :                         rebuild_object_properties(zobj1);
    1433             :                 }
    1434         299 :                 if (!zobj2->properties) {
    1435           2 :                         rebuild_object_properties(zobj2);
    1436             :                 }
    1437         299 :                 return zend_compare_symbol_tables_i(zobj1->properties, zobj2->properties TSRMLS_CC);
    1438             :         }
    1439             : }
    1440             : /* }}} */
    1441             : 
    1442         283 : static int zend_std_has_property(zval *object, zval *member, int has_set_exists, void **cache_slot TSRMLS_DC) /* {{{ */
    1443             : {
    1444             :         zend_object *zobj;
    1445             :         int result;
    1446         283 :         zval *value = NULL;
    1447             :         zval tmp_member;
    1448             :         zend_property_info *property_info;
    1449             : 
    1450         283 :         zobj = Z_OBJ_P(object);
    1451             : 
    1452         283 :         ZVAL_UNDEF(&tmp_member);
    1453         283 :         if (UNEXPECTED(Z_TYPE_P(member) != IS_STRING)) {
    1454           4 :                 ZVAL_DUP(&tmp_member, member);
    1455           4 :                 convert_to_string(&tmp_member);
    1456           4 :                 member = &tmp_member;
    1457           4 :                 cache_slot = NULL;
    1458             :         }
    1459             : 
    1460         566 :         property_info = zend_get_property_info_quick(zobj->ce, Z_STR_P(member), 1, cache_slot TSRMLS_CC);
    1461             : 
    1462         283 :         if (EXPECTED(property_info != NULL)) {
    1463         564 :                 if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
    1464         264 :                     property_info->offset >= 0) {
    1465         124 :                         value = &zobj->properties_table[property_info->offset];
    1466         124 :                         if (Z_TYPE_P(value) != IS_UNDEF) {
    1467          89 :                                 goto found;
    1468             :                         }
    1469         222 :                 } else if (UNEXPECTED(zobj->properties != NULL) &&
    1470          81 :                            (value = zend_hash_find(zobj->properties, property_info->name)) != NULL) {
    1471             : found:
    1472         126 :                         switch (has_set_exists) {
    1473             :                                 case 0:
    1474          70 :                                         ZVAL_DEREF(value);
    1475          70 :                                         result = (Z_TYPE_P(value) != IS_NULL);
    1476          70 :                                         break;
    1477             :                                 default:
    1478          24 :                                         result = zend_is_true(value TSRMLS_CC);
    1479          24 :                                         break;
    1480             :                                 case 2:
    1481          32 :                                         result = 1;
    1482             :                                         break;
    1483             :                         }
    1484         126 :                         goto exit;
    1485             :                 }
    1486             :         }
    1487             : 
    1488         157 :         result = 0;
    1489         157 :         if ((has_set_exists != 2) && zobj->ce->__isset) {
    1490          31 :                 zend_long *guard = zend_get_property_guard(zobj, property_info, member);
    1491             : 
    1492          31 :                 if (!((*guard) & IN_ISSET)) {
    1493             :                         zval rv;
    1494             :                         zval tmp_object;
    1495             : 
    1496             :                         /* have issetter - try with it! */
    1497          20 :                         ZVAL_COPY(&tmp_object, object);
    1498          20 :                         (*guard) |= IN_ISSET; /* prevent circular getting */
    1499          20 :                         zend_std_call_issetter(&tmp_object, member, &rv TSRMLS_CC);
    1500          20 :                         if (Z_TYPE(rv) != IS_UNDEF) {
    1501          20 :                                 result = zend_is_true(&rv TSRMLS_CC);
    1502          20 :                                 zval_ptr_dtor(&rv);
    1503          20 :                                 if (has_set_exists && result) {
    1504           3 :                                         if (EXPECTED(!EG(exception)) && zobj->ce->__get && !((*guard) & IN_GET)) {
    1505           1 :                                                 (*guard) |= IN_GET;
    1506           1 :                                                 zend_std_call_getter(&tmp_object, member, &rv TSRMLS_CC);
    1507           1 :                                                 (*guard) &= ~IN_GET;
    1508           1 :                                                 if (Z_TYPE(rv) != IS_UNDEF) {
    1509           1 :                                                         result = i_zend_is_true(&rv TSRMLS_CC);
    1510           1 :                                                         zval_ptr_dtor(&rv);
    1511             :                                                 } else {
    1512           0 :                                                         result = 0;
    1513             :                                                 }
    1514             :                                         } else {
    1515           1 :                                                 result = 0;
    1516             :                                         }
    1517             :                                 }
    1518             :                         }
    1519          20 :                         (*guard) &= ~IN_ISSET;
    1520          20 :                         zval_ptr_dtor(&tmp_object);
    1521             :                 }
    1522             :         }
    1523             : 
    1524             : exit:
    1525         283 :         if (UNEXPECTED(Z_TYPE(tmp_member) != IS_UNDEF)) {
    1526           4 :                 zval_ptr_dtor(&tmp_member);
    1527             :         }
    1528         283 :         return result;
    1529             : }
    1530             : /* }}} */
    1531             : 
    1532     3047102 : zend_class_entry *zend_std_object_get_class(const zend_object *object TSRMLS_DC) /* {{{ */
    1533             : {
    1534     3047102 :         return object->ce;
    1535             : }
    1536             : /* }}} */
    1537             : 
    1538      137111 : zend_string* zend_std_object_get_class_name(const zend_object *zobj, int parent TSRMLS_DC) /* {{{ */
    1539             : {
    1540             :         zend_class_entry *ce;
    1541             : 
    1542      137111 :         if (parent) {
    1543          11 :                 if (!zobj->ce->parent) {
    1544           8 :                         return NULL;
    1545             :                 }
    1546           3 :                 ce = zobj->ce->parent;
    1547             :         } else {
    1548      137100 :                 ce = zobj->ce;
    1549             :         }
    1550             : 
    1551      274206 :         return zend_string_copy(ce->name);
    1552             : }
    1553             : /* }}} */
    1554             : 
    1555      397135 : ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int type TSRMLS_DC) /* {{{ */
    1556             : {
    1557             :         zval retval;
    1558             :         zend_class_entry *ce;
    1559             : 
    1560      397135 :         switch (type) {
    1561             :                 case IS_STRING:
    1562      304483 :                         ce = Z_OBJCE_P(readobj);
    1563      608328 :                         if (ce->__tostring &&
    1564      303845 :                                 (zend_call_method_with_0_params(readobj, ce, &ce->__tostring, "__tostring", &retval) || EG(exception))) {
    1565      303845 :                                 if (UNEXPECTED(EG(exception) != NULL)) {
    1566           4 :                                         zval_ptr_dtor(&retval);
    1567           4 :                                         EG(exception) = NULL;
    1568           4 :                                         zend_error_noreturn(E_ERROR, "Method %s::__toString() must not throw an exception", ce->name->val);
    1569             :                                         return FAILURE;
    1570             :                                 }
    1571      303841 :                                 if (EXPECTED(Z_TYPE(retval) == IS_STRING)) {
    1572      303837 :                                         if (readobj == writeobj) {
    1573           0 :                                                 zval_ptr_dtor(readobj);
    1574             :                                         }
    1575      303837 :                                         ZVAL_COPY_VALUE(writeobj, &retval);
    1576      303837 :                                         return SUCCESS;
    1577             :                                 } else {
    1578           4 :                                         zval_ptr_dtor(&retval);
    1579           4 :                                         if (readobj == writeobj) {
    1580           0 :                                                 zval_ptr_dtor(readobj);
    1581             :                                         }
    1582           4 :                                         ZVAL_EMPTY_STRING(writeobj);
    1583           4 :                                         zend_error(E_RECOVERABLE_ERROR, "Method %s::__toString() must return a string value", ce->name->val);
    1584           4 :                                         return SUCCESS;
    1585             :                                 }
    1586             :                         }
    1587         638 :                         return FAILURE;
    1588             :                 case _IS_BOOL:
    1589       92401 :                         ZVAL_BOOL(writeobj, 1);
    1590       92401 :                         return SUCCESS;
    1591             :                 case IS_LONG:
    1592         143 :                         ce = Z_OBJCE_P(readobj);
    1593         143 :                         zend_error(E_NOTICE, "Object of class %s could not be converted to int", ce->name->val);
    1594         143 :                         if (readobj == writeobj) {
    1595             :                                 zval_dtor(readobj);
    1596             :                         }
    1597         143 :                         ZVAL_LONG(writeobj, 1);
    1598         143 :                         return SUCCESS;
    1599             :                 case IS_DOUBLE:
    1600          43 :                         ce = Z_OBJCE_P(readobj);
    1601          43 :                         zend_error(E_NOTICE, "Object of class %s could not be converted to double", ce->name->val);
    1602          43 :                         if (readobj == writeobj) {
    1603             :                                 zval_dtor(readobj);
    1604             :                         }
    1605          43 :                         ZVAL_DOUBLE(writeobj, 1);
    1606          43 :                         return SUCCESS;
    1607             :                 default:
    1608          65 :                         ZVAL_NULL(writeobj);
    1609             :                         break;
    1610             :         }
    1611          65 :         return FAILURE;
    1612             : }
    1613             : /* }}} */
    1614             : 
    1615          71 : int zend_std_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr TSRMLS_DC) /* {{{ */
    1616             : {
    1617             :         zval *func;
    1618             :         zend_class_entry *ce;
    1619             : 
    1620          71 :         if (Z_TYPE_P(obj) != IS_OBJECT) {
    1621           0 :                 return FAILURE;
    1622             :         }
    1623             : 
    1624          71 :         ce = Z_OBJCE_P(obj);
    1625             : 
    1626          71 :         if ((func = zend_hash_str_find(&ce->function_table, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1)) == NULL) {
    1627          50 :                 return FAILURE;
    1628             :         }
    1629          21 :         *fptr_ptr = Z_FUNC_P(func);
    1630             : 
    1631          21 :         *ce_ptr = ce;
    1632          21 :         if ((*fptr_ptr)->common.fn_flags & ZEND_ACC_STATIC) {
    1633           0 :                 if (obj_ptr) {
    1634           0 :                         *obj_ptr = NULL;
    1635             :                 }
    1636             :         } else {
    1637          21 :                 if (obj_ptr) {
    1638          21 :                         *obj_ptr = Z_OBJ_P(obj);
    1639             :                 }
    1640             :         }
    1641          21 :         return SUCCESS;
    1642             : }
    1643             : /* }}} */
    1644             : 
    1645             : ZEND_API zend_object_handlers std_object_handlers = {
    1646             :         0,                                                                              /* offset */
    1647             : 
    1648             :         zend_object_std_dtor,                                   /* free_obj */
    1649             :         zend_objects_destroy_object,                    /* dtor_obj */
    1650             :         zend_objects_clone_obj,                                 /* clone_obj */
    1651             : 
    1652             :         zend_std_read_property,                                 /* read_property */
    1653             :         zend_std_write_property,                                /* write_property */
    1654             :         zend_std_read_dimension,                                /* read_dimension */
    1655             :         zend_std_write_dimension,                               /* write_dimension */
    1656             :         zend_std_get_property_ptr_ptr,                  /* get_property_ptr_ptr */
    1657             :         NULL,                                                                   /* get */
    1658             :         NULL,                                                                   /* set */
    1659             :         zend_std_has_property,                                  /* has_property */
    1660             :         zend_std_unset_property,                                /* unset_property */
    1661             :         zend_std_has_dimension,                                 /* has_dimension */
    1662             :         zend_std_unset_dimension,                               /* unset_dimension */
    1663             :         zend_std_get_properties,                                /* get_properties */
    1664             :         zend_std_get_method,                                    /* get_method */
    1665             :         NULL,                                                                   /* call_method */
    1666             :         zend_std_get_constructor,                               /* get_constructor */
    1667             :         zend_std_object_get_class,                              /* get_class_entry */
    1668             :         zend_std_object_get_class_name,                 /* get_class_name */
    1669             :         zend_std_compare_objects,                               /* compare_objects */
    1670             :         zend_std_cast_object_tostring,                  /* cast_object */
    1671             :         NULL,                                                                   /* count_elements */
    1672             :         zend_std_get_debug_info,                                /* get_debug_info */
    1673             :         zend_std_get_closure,                                   /* get_closure */
    1674             :         zend_std_get_gc,                                                /* get_gc */
    1675             :         NULL,                                                                   /* do_operation */
    1676             :         NULL,                                                                   /* compare */
    1677             : };
    1678             : 
    1679             : /*
    1680             :  * Local variables:
    1681             :  * tab-width: 4
    1682             :  * c-basic-offset: 4
    1683             :  * indent-tabs-mode: t
    1684             :  * End:
    1685             :  */

Generated by: LCOV version 1.10

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

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