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: 683 737 92.7 %
Date: 2015-01-26 Functions: 35 36 97.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Mon, 26 Jan 2015 14:46:40 +0000 (5 hours ago)

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