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

Generated by: LCOV version 1.10

Generated at Thu, 30 Oct 2014 07:41:26 +0000 (46 hours ago)

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