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: 696 754 92.3 %
Date: 2015-05-21 Functions: 34 34 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Thu, 21 May 2015 19:58:51 +0000 (7 days ago)

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