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

Generated by: LCOV version 1.10

Generated at Sat, 22 Nov 2014 23:01:11 +0000 (6 hours ago)

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