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: 757 816 92.8 %
Date: 2014-09-21 Functions: 35 37 94.6 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Sun, 21 Sep 2014 15:27:30 +0000 (46 hours ago)

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