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: 691 743 93.0 %
Date: 2015-04-14 Functions: 36 37 97.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Tue, 14 Apr 2015 11:48:38 +0000 (11 days ago)

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