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: 679 735 92.4 %
Date: 2014-10-22 Functions: 35 36 97.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Wed, 22 Oct 2014 07:24:44 +0000 (3 days ago)

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