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: 703 769 91.4 %
Date: 2015-06-27 Functions: 34 34 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Sat, 27 Jun 2015 09:41:05 +0000 (7 days ago)

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