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: 661 712 92.8 %
Date: 2014-12-13 Functions: 35 36 97.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Sat, 13 Dec 2014 06:16:08 +0000 (4 days ago)

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