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: 622 666 93.4 %
Date: 2014-07-27 Functions: 36 38 94.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2013 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) zend_objects_get_address(zval_p TSRMLS_CC)
      36             : 
      37             : /*
      38             :   __X accessors explanation:
      39             : 
      40             :   if we have __get and property that is not part of the properties array is
      41             :   requested, we call __get handler. If it fails, we return uninitialized.
      42             : 
      43             :   if we have __set and property that is not part of the properties array is
      44             :   set, we call __set handler. If it fails, we do not change the array.
      45             : 
      46             :   for both handlers above, when we are inside __get/__set, no further calls for
      47             :   __get/__set for this property of this object will be made, to prevent endless
      48             :   recursion and enable accessors to change properties array.
      49             : 
      50             :   if we have __call and method which is not part of the class function table is
      51             :   called, we cal __call handler.
      52             : */
      53             : 
      54      989045 : ZEND_API HashTable *zend_std_get_properties(zval *object TSRMLS_DC) /* {{{ */
      55             : {
      56             :         zend_object *zobj;
      57      989045 :         zobj = Z_OBJ_P(object);
      58      989045 :         return zobj->properties;
      59             : }
      60             : /* }}} */
      61             : 
      62           0 : ZEND_API HashTable *zend_std_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
      63             : {
      64           0 :         *is_temp = 0;
      65           0 :         return zend_std_get_properties(object TSRMLS_CC);
      66             : }
      67             : /* }}} */
      68             : 
      69         125 : static zval *zend_std_call_getter(zval *object, zval *member TSRMLS_DC) /* {{{ */
      70             : {
      71         125 :         zval *retval = NULL;
      72         125 :         zend_class_entry *ce = Z_OBJCE_P(object);
      73             : 
      74             :         /* __get handler is called with one argument:
      75             :               property name
      76             : 
      77             :            it should return whether the call was successfull or not
      78             :         */
      79             : 
      80         468 :         SEPARATE_ARG_IF_REF(member);
      81             : 
      82         125 :         zend_call_method_with_1_params(&object, ce, &ce->__get, ZEND_GET_FUNC_NAME, &retval, member);
      83             : 
      84         124 :         zval_ptr_dtor(&member);
      85             : 
      86         124 :         if (retval) {
      87         122 :                 Z_DELREF_P(retval);
      88             :         }
      89             : 
      90         124 :         return retval;
      91             : }
      92             : /* }}} */
      93             : 
      94          93 : static int zend_std_call_setter(zval *object, zval *member, zval *value TSRMLS_DC) /* {{{ */
      95             : {
      96          93 :         zval *retval = NULL;
      97             :         int result;
      98          93 :         zend_class_entry *ce = Z_OBJCE_P(object);
      99             : 
     100         308 :         SEPARATE_ARG_IF_REF(member);
     101          93 :         Z_ADDREF_P(value);
     102             : 
     103             :         /* __set handler is called with two arguments:
     104             :              property name
     105             :              value to be set
     106             : 
     107             :            it should return whether the call was successfull or not
     108             :         */
     109          93 :         zend_call_method_with_2_params(&object, ce, &ce->__set, ZEND_SET_FUNC_NAME, &retval, member, value);
     110             : 
     111          92 :         zval_ptr_dtor(&member);
     112          92 :         zval_ptr_dtor(&value);
     113             : 
     114          92 :         if (retval) {
     115          91 :                 result = i_zend_is_true(retval) ? SUCCESS : FAILURE;
     116          91 :                 zval_ptr_dtor(&retval);
     117          91 :                 return result;
     118             :         } else {
     119           1 :                 return FAILURE;
     120             :         }
     121             : }
     122             : /* }}} */
     123             : 
     124           8 : static void zend_std_call_unsetter(zval *object, zval *member TSRMLS_DC) /* {{{ */
     125             : {
     126           8 :         zend_class_entry *ce = Z_OBJCE_P(object);
     127             : 
     128             :         /* __unset handler is called with one argument:
     129             :               property name
     130             :         */
     131             : 
     132          26 :         SEPARATE_ARG_IF_REF(member);
     133             : 
     134           8 :         zend_call_method_with_1_params(&object, ce, &ce->__unset, ZEND_UNSET_FUNC_NAME, NULL, member);
     135             : 
     136           7 :         zval_ptr_dtor(&member);
     137           7 : }
     138             : /* }}} */
     139             : 
     140          11 : static zval *zend_std_call_issetter(zval *object, zval *member TSRMLS_DC) /* {{{ */
     141             : {
     142          11 :         zval *retval = NULL;
     143          11 :         zend_class_entry *ce = Z_OBJCE_P(object);
     144             : 
     145             :         /* __isset handler is called with one argument:
     146             :               property name
     147             : 
     148             :            it should return whether the property is set or not
     149             :         */
     150             : 
     151          44 :         SEPARATE_ARG_IF_REF(member);
     152             : 
     153          11 :         zend_call_method_with_1_params(&object, ce, &ce->__isset, ZEND_ISSET_FUNC_NAME, &retval, member);
     154             : 
     155          11 :         zval_ptr_dtor(&member);
     156             : 
     157          11 :         return retval;
     158             : }
     159             : /* }}} */
     160             : 
     161      313059 : static int zend_verify_property_access(zend_property_info *property_info, zend_class_entry *ce TSRMLS_DC) /* {{{ */
     162             : {
     163      313059 :         switch (property_info->flags & ZEND_ACC_PPP_MASK) {
     164             :                 case ZEND_ACC_PUBLIC:
     165      295724 :                         return 1;
     166             :                 case ZEND_ACC_PROTECTED:
     167        7733 :                         return zend_check_protected(property_info->ce, EG(scope));
     168             :                 case ZEND_ACC_PRIVATE:
     169        9602 :                         if ((ce==EG(scope) || property_info->ce == EG(scope)) && EG(scope)) {
     170        9484 :                                 return 1;
     171             :                         } else {
     172         118 :                                 return 0;
     173             :                         }
     174             :                         break;
     175             :         }
     176           0 :         return 0;
     177             : }
     178             : /* }}} */
     179             : 
     180      437968 : static inline zend_bool is_derived_class(zend_class_entry *child_class, zend_class_entry *parent_class) /* {{{ */
     181             : {
     182      437968 :         child_class = child_class->parent;
     183      878468 :         while (child_class) {
     184        4960 :                 if (child_class == parent_class) {
     185        2428 :                         return 1;
     186             :                 }
     187        2532 :                 child_class = child_class->parent;
     188             :         }
     189             : 
     190      435540 :         return 0;
     191             : }
     192             : /* }}} */
     193             : 
     194      745691 : ZEND_API struct _zend_property_info *zend_get_property_info(zend_class_entry *ce, zval *member, int silent TSRMLS_DC) /* {{{ */
     195             : {
     196      745691 :         zend_property_info *property_info = NULL;
     197             :         zend_property_info *scope_property_info;
     198      745691 :         zend_bool denied_access = 0;
     199             :         ulong h;
     200             : 
     201      745691 :         if (Z_STRVAL_P(member)[0] == '\0') {
     202          17 :                 if (!silent) {
     203           1 :                         if (Z_STRLEN_P(member) == 0) {
     204           1 :                                 zend_error(E_ERROR, "Cannot access empty property");
     205             :                         } else {
     206           0 :                                 zend_error(E_ERROR, "Cannot access property started with '\\0'");
     207             :                         }
     208             :                 }
     209          16 :                 return NULL;
     210             :         }
     211      745674 :         h = zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member) + 1);
     212      745674 :         if (zend_hash_quick_find(&ce->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, h, (void **) &property_info)==SUCCESS) {
     213      314015 :                 if(property_info->flags & ZEND_ACC_SHADOW) {
     214             :                         /* if it's a shadow - go to access it's private */
     215        2271 :                         property_info = NULL;
     216             :                 } else {
     217      311744 :                         if (zend_verify_property_access(property_info, ce TSRMLS_CC)) {
     218      623190 :                                 if (property_info->flags & ZEND_ACC_CHANGED
     219      311615 :                                         && !(property_info->flags & ZEND_ACC_PRIVATE)) {
     220             :                                         /* We still need to make sure that we're not in a context
     221             :                                          * where the right property is a different 'statically linked' private
     222             :                                          * continue checking below...
     223             :                                          */
     224             :                                 } else {
     225      311554 :                                         if (!silent && (property_info->flags & ZEND_ACC_STATIC)) {
     226          12 :                                                 zend_error(E_STRICT, "Accessing static property %s::$%s as non static", ce->name, Z_STRVAL_P(member));
     227             :                                         }
     228      311554 :                                         return property_info;
     229             :                                 }
     230             :                         } else {
     231             :                                 /* Try to look in the scope instead */
     232         169 :                                 denied_access = 1;
     233             :                         }
     234             :                 }
     235             :         }
     236      870976 :         if (EG(scope) != ce
     237             :                 && is_derived_class(ce, EG(scope))
     238      432191 :                 && EG(scope)
     239        4836 :                 && zend_hash_quick_find(&EG(scope)->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, h, (void **) &scope_property_info)==SUCCESS
     240        9501 :                 && scope_property_info->flags & ZEND_ACC_PRIVATE) {
     241        2239 :                 return scope_property_info;
     242      431881 :         } else if (property_info) {
     243         165 :                 if (denied_access) {
     244             :                         /* Information was available, but we were denied access.  Error out. */
     245         155 :                         if (silent) {
     246         139 :                                 return NULL;
     247             :                         }
     248          16 :                         zend_error(E_ERROR, "Cannot access %s property %s::$%s", zend_visibility_string(property_info->flags), ce->name, Z_STRVAL_P(member));
     249             :                 } else {
     250             :                         /* fall through, return property_info... */
     251             :                 }
     252             :         } else {
     253      431716 :                 EG(std_property_info).flags = ZEND_ACC_PUBLIC;
     254      431716 :                 EG(std_property_info).name = Z_STRVAL_P(member);
     255      431716 :                 EG(std_property_info).name_length = Z_STRLEN_P(member);
     256      431716 :                 EG(std_property_info).h = h;
     257      431716 :                 EG(std_property_info).ce = ce;
     258      431716 :                 property_info = &EG(std_property_info);
     259             :         }
     260      431726 :         return property_info;
     261             : }
     262             : /* }}} */
     263             : 
     264         616 : ZEND_API int zend_check_property_access(zend_object *zobj, char *prop_info_name, int prop_info_name_len TSRMLS_DC) /* {{{ */
     265             : {
     266             :         zend_property_info *property_info;
     267             :         char *class_name, *prop_name;
     268             :         zval member;
     269             : 
     270         616 :         zend_unmangle_property_name(prop_info_name, prop_info_name_len, &class_name, &prop_name);
     271         616 :         ZVAL_STRING(&member, prop_name, 0);
     272         616 :         property_info = zend_get_property_info(zobj->ce, &member, 1 TSRMLS_CC);
     273         616 :         if (!property_info) {
     274          71 :                 return FAILURE;
     275             :         }
     276         545 :         if (class_name && class_name[0] != '*') {
     277          87 :                 if (!(property_info->flags & ZEND_ACC_PRIVATE)) {
     278             :                         /* we we're looking for a private prop but found a non private one of the same name */
     279          18 :                         return FAILURE;
     280          69 :                 } else if (strcmp(prop_info_name+1, property_info->name+1)) {
     281             :                         /* we we're looking for a private prop but found a private one of the same name but another class */
     282          11 :                         return FAILURE;
     283             :                 }
     284             :         }
     285         516 :         return zend_verify_property_access(property_info, zobj->ce TSRMLS_CC) ? SUCCESS : FAILURE;
     286             : }
     287             : /* }}} */
     288             : 
     289         298 : static int zend_get_property_guard(zend_object *zobj, zend_property_info *property_info, zval *member, zend_guard **pguard) /* {{{ */
     290             : {
     291             :         zend_property_info info;
     292             :         zend_guard stub;
     293             : 
     294         298 :         if (!property_info) {
     295          40 :                 property_info = &info;
     296          40 :                 info.name = Z_STRVAL_P(member);
     297          40 :                 info.name_length = Z_STRLEN_P(member);
     298          40 :                 info.h = zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member) + 1);
     299         258 :         } else if(property_info->name[0] == '\0'){
     300           6 :                 const char *class_name = NULL, *prop_name = NULL;
     301           6 :                 zend_unmangle_property_name(property_info->name, property_info->name_length, &class_name, &prop_name);
     302           6 :                 if(class_name) {
     303             :                         /* use unmangled name for protected properties */
     304           6 :                         info.name = prop_name;
     305           6 :                         info.name_length = strlen(prop_name);
     306           6 :                         info.h = zend_get_hash_value(info.name, info.name_length+1);
     307           6 :                         property_info = &info;
     308             :                 }
     309             :         }
     310         298 :         if (!zobj->guards) {
     311          66 :                 ALLOC_HASHTABLE(zobj->guards);
     312          66 :                 zend_hash_init(zobj->guards, 0, NULL, NULL, 0);
     313         232 :         } else if (zend_hash_quick_find(zobj->guards, property_info->name, property_info->name_length+1, property_info->h, (void **) pguard) == SUCCESS) {
     314         183 :                 return SUCCESS;
     315             :         }
     316         115 :         stub.in_get = 0;
     317         115 :         stub.in_set = 0;
     318         115 :         stub.in_unset = 0;
     319         115 :         stub.in_isset = 0;
     320         115 :         return zend_hash_quick_add(zobj->guards, property_info->name, property_info->name_length+1, property_info->h, (void**)&stub, sizeof(stub), (void**) pguard);
     321             : }
     322             : /* }}} */
     323             : 
     324       35884 : zval *zend_std_read_property(zval *object, zval *member, int type TSRMLS_DC) /* {{{ */
     325             : {
     326             :         zend_object *zobj;
     327       35884 :         zval *tmp_member = NULL;
     328             :         zval **retval;
     329       35884 :         zval *rv = NULL;
     330             :         zend_property_info *property_info;
     331             :         int silent;
     332             : 
     333       35884 :         silent = (type == BP_VAR_IS);
     334       35884 :         zobj = Z_OBJ_P(object);
     335             : 
     336       35884 :         if (Z_TYPE_P(member) != IS_STRING) {
     337           7 :                 ALLOC_ZVAL(tmp_member);
     338           7 :                 *tmp_member = *member;
     339           7 :                 INIT_PZVAL(tmp_member);
     340           7 :                 zval_copy_ctor(tmp_member);
     341           7 :                 convert_to_string(tmp_member);
     342           7 :                 member = tmp_member;
     343             :         }
     344             : 
     345             : #if DEBUG_OBJECT_HANDLERS
     346             :         fprintf(stderr, "Read object #%d property: %s\n", Z_OBJ_HANDLE_P(object), Z_STRVAL_P(member));
     347             : #endif
     348             : 
     349             :         /* make zend_get_property_info silent if we have getter - we may want to use it */
     350       35884 :         property_info = zend_get_property_info(zobj->ce, member, (zobj->ce->__get != NULL) TSRMLS_CC);
     351             : 
     352       35880 :         if (!property_info || zend_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &retval) == FAILURE) {
     353         358 :                 zend_guard *guard = NULL;
     354             : 
     355         741 :                 if (zobj->ce->__get &&
     356         130 :                     zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS &&
     357         130 :                     !guard->in_get) {
     358             :                         /* have getter - try with it! */
     359         124 :                         Z_ADDREF_P(object);
     360         248 :                         if (PZVAL_IS_REF(object)) {
     361           4 :                                 SEPARATE_ZVAL(&object);
     362             :                         }
     363         124 :                         guard->in_get = 1; /* prevent circular getting */
     364         124 :                         rv = zend_std_call_getter(object, member TSRMLS_CC);
     365         123 :                         guard->in_get = 0;
     366             : 
     367         123 :                         if (rv) {
     368         121 :                                 retval = &rv;
     369         242 :                                 if (!Z_ISREF_P(rv) &&
     370             :                                     (type == BP_VAR_W || type == BP_VAR_RW  || type == BP_VAR_UNSET)) {
     371          38 :                                         if (Z_REFCOUNT_P(rv) > 0) {
     372          10 :                                                 zval *tmp = rv;
     373             : 
     374          10 :                                                 ALLOC_ZVAL(rv);
     375          10 :                                                 *rv = *tmp;
     376          10 :                                                 zval_copy_ctor(rv);
     377          10 :                                                 Z_UNSET_ISREF_P(rv);
     378          10 :                                                 Z_SET_REFCOUNT_P(rv, 0);
     379             :                                         }
     380          19 :                                         if (Z_TYPE_P(rv) != IS_OBJECT) {
     381          13 :                                                 zend_error(E_NOTICE, "Indirect modification of overloaded property %s::$%s has no effect", zobj->ce->name, Z_STRVAL_P(member));
     382             :                                         }
     383             :                                 }
     384             :                         } else {
     385           2 :                                 retval = &EG(uninitialized_zval_ptr);
     386             :                         }
     387         123 :                         if (EXPECTED(*retval != object)) {
     388         122 :                                 zval_ptr_dtor(&object);
     389             :                         } else {
     390           1 :                                 Z_DELREF_P(object);
     391             :                         }
     392             :                 } else {
     393         234 :                         if (zobj->ce->__get && guard && guard->in_get == 1) {
     394           6 :                                 if (Z_STRVAL_P(member)[0] == '\0') {
     395           1 :                                         if (Z_STRLEN_P(member) == 0) {
     396           1 :                                                 zend_error(E_ERROR, "Cannot access empty property");
     397             :                                         } else {
     398           0 :                                                 zend_error(E_ERROR, "Cannot access property started with '\\0'");
     399             :                                         }
     400             :                                 }
     401             :                         }
     402         233 :                         if (!silent) {
     403          47 :                                 zend_error(E_NOTICE,"Undefined property: %s::$%s", zobj->ce->name, Z_STRVAL_P(member));
     404             :                         }
     405         233 :                         retval = &EG(uninitialized_zval_ptr);
     406             :                 }
     407             :         }
     408       35878 :         if (tmp_member) {
     409           6 :                 Z_ADDREF_PP(retval);
     410           6 :                 zval_ptr_dtor(&tmp_member);
     411           6 :                 Z_DELREF_PP(retval);
     412             :         }
     413       35878 :         return *retval;
     414             : }
     415             : /* }}} */
     416             : 
     417      528725 : static void zend_std_write_property(zval *object, zval *member, zval *value TSRMLS_DC) /* {{{ */
     418             : {
     419             :         zend_object *zobj;
     420      528725 :         zval *tmp_member = NULL;
     421             :         zval **variable_ptr;
     422             :         zend_property_info *property_info;
     423             : 
     424      528725 :         zobj = Z_OBJ_P(object);
     425             : 
     426      528725 :         if (Z_TYPE_P(member) != IS_STRING) {
     427           7 :                 ALLOC_ZVAL(tmp_member);
     428           7 :                 *tmp_member = *member;
     429           7 :                 INIT_PZVAL(tmp_member);
     430           7 :                 zval_copy_ctor(tmp_member);
     431           7 :                 convert_to_string(tmp_member);
     432           7 :                 member = tmp_member;
     433             :         }
     434             : 
     435      528725 :         property_info = zend_get_property_info(zobj->ce, member, (zobj->ce->__set != NULL) TSRMLS_CC);
     436             : 
     437      629467 :         if (property_info && zend_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &variable_ptr) == SUCCESS) {
     438             :                 /* if we already have this value there, we don't actually need to do anything */
     439      100753 :                 if (*variable_ptr != value) {
     440             :                         /* if we are assigning reference, we shouldn't move it, but instead assign variable
     441             :                            to the same pointer */
     442      201480 :                         if (PZVAL_IS_REF(*variable_ptr)) {
     443          42 :                                 zval garbage = **variable_ptr; /* old value should be destroyed */
     444             : 
     445             :                                 /* To check: can't *variable_ptr be some system variable like error_zval here? */
     446          42 :                                 Z_TYPE_PP(variable_ptr) = Z_TYPE_P(value);
     447          42 :                                 (*variable_ptr)->value = value->value;
     448          84 :                                 if (Z_REFCOUNT_P(value) > 0) {
     449          42 :                                         zval_copy_ctor(*variable_ptr);
     450             :                                 } else {
     451           0 :                                         efree(value);
     452             :                                 }
     453          42 :                                 zval_dtor(&garbage);
     454             :                         } else {
     455      100698 :                                 zval *garbage = *variable_ptr;
     456             : 
     457             :                                 /* if we assign referenced variable, we should separate it */
     458      100698 :                                 Z_ADDREF_P(value);
     459      201396 :                                 if (PZVAL_IS_REF(value)) {
     460          28 :                                         SEPARATE_ZVAL(&value);
     461             :                                 }
     462      100698 :                                 *variable_ptr = value;
     463      100698 :                                 zval_ptr_dtor(&garbage);
     464             :                         }
     465             :                 }
     466             :         } else {
     467      427961 :                 zend_guard *guard = NULL;
     468             : 
     469      428265 :                 if (zobj->ce->__set &&
     470         106 :                     zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS &&
     471         106 :                     !guard->in_set) {
     472          93 :                         Z_ADDREF_P(object);
     473         186 :                         if (PZVAL_IS_REF(object)) {
     474           4 :                                 SEPARATE_ZVAL(&object);
     475             :                         }
     476          93 :                         guard->in_set = 1; /* prevent circular setting */
     477          93 :                         if (zend_std_call_setter(object, member, value TSRMLS_CC) != SUCCESS) {
     478             :                                 /* for now, just ignore it - __set should take care of warnings, etc. */
     479             :                         }
     480          92 :                         guard->in_set = 0;
     481          92 :                         zval_ptr_dtor(&object);
     482      427868 :                 } else if (property_info) {
     483             :                         zval **foo;
     484             : 
     485             :                         /* if we assign referenced variable, we should separate it */
     486      427866 :                         Z_ADDREF_P(value);
     487      855732 :                         if (PZVAL_IS_REF(value)) {
     488       40054 :                                 SEPARATE_ZVAL(&value);
     489             :                         }
     490      427866 :                         zend_hash_quick_update(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, &value, sizeof(zval *), (void **) &foo);
     491           2 :                 } else if (zobj->ce->__set && guard && guard->in_set == 1) {
     492           2 :                         if (Z_STRVAL_P(member)[0] == '\0') {
     493           1 :                                 if (Z_STRLEN_P(member) == 0) {
     494           1 :                                         zend_error(E_ERROR, "Cannot access empty property");
     495             :                                 } else {
     496           0 :                                         zend_error(E_ERROR, "Cannot access property started with '\\0'");
     497             :                                 }
     498             :                         }
     499             :                 }
     500             :         }
     501             : 
     502      528712 :         if (tmp_member) {
     503           6 :                 zval_ptr_dtor(&tmp_member);
     504             :         }
     505      528712 : }
     506             : /* }}} */
     507             : 
     508         475 : zval *zend_std_read_dimension(zval *object, zval *offset, int type TSRMLS_DC) /* {{{ */
     509             : {
     510         475 :         zend_class_entry *ce = Z_OBJCE_P(object);
     511             :         zval *retval;
     512             : 
     513         475 :         if (instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC)) {
     514         472 :                 if(offset == NULL) {
     515             :                         /* [] construct */
     516           0 :                         ALLOC_INIT_ZVAL(offset);
     517             :                 } else {
     518        1774 :                         SEPARATE_ARG_IF_REF(offset);
     519             :                 }
     520         472 :                 zend_call_method_with_1_params(&object, ce, NULL, "offsetget", &retval, offset);
     521             : 
     522         472 :                 zval_ptr_dtor(&offset);
     523             : 
     524         472 :                 if (!retval) {
     525           5 :                         if (!EG(exception)) {
     526           0 :                                 zend_error(E_ERROR, "Undefined offset for object of type %s used as array", ce->name);
     527             :                         }
     528           5 :                         return 0;
     529             :                 }
     530             : 
     531             :                 /* Undo PZVAL_LOCK() */
     532         467 :                 Z_DELREF_P(retval);
     533             : 
     534         467 :                 return retval;
     535             :         } else {
     536           3 :                 zend_error(E_ERROR, "Cannot use object of type %s as array", ce->name);
     537           0 :                 return 0;
     538             :         }
     539             : }
     540             : /* }}} */
     541             : 
     542         316 : static void zend_std_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) /* {{{ */
     543             : {
     544         316 :         zend_class_entry *ce = Z_OBJCE_P(object);
     545             : 
     546         316 :         if (instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC)) {
     547         315 :                 if (!offset) {
     548          10 :                         ALLOC_INIT_ZVAL(offset);
     549             :                 } else {
     550        1056 :                         SEPARATE_ARG_IF_REF(offset);
     551             :                 }
     552         315 :                 zend_call_method_with_2_params(&object, ce, NULL, "offsetset", NULL, offset, value);
     553         315 :                 zval_ptr_dtor(&offset);
     554             :         } else {
     555           1 :                 zend_error(E_ERROR, "Cannot use object of type %s as array", ce->name);
     556             :         }
     557         315 : }
     558             : /* }}} */
     559             : 
     560          78 : static int zend_std_has_dimension(zval *object, zval *offset, int check_empty TSRMLS_DC) /* {{{ */
     561             : {
     562          78 :         zend_class_entry *ce = Z_OBJCE_P(object);
     563             :         zval *retval;
     564             :         int result;
     565             : 
     566          78 :         if (instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC)) {
     567         296 :                 SEPARATE_ARG_IF_REF(offset);
     568          78 :                 zend_call_method_with_1_params(&object, ce, NULL, "offsetexists", &retval, offset);
     569          78 :                 if (retval) {
     570          76 :                         result = i_zend_is_true(retval);
     571          76 :                         zval_ptr_dtor(&retval);
     572          76 :                         if (check_empty && result && !EG(exception)) {
     573           8 :                                 zend_call_method_with_1_params(&object, ce, NULL, "offsetget", &retval, offset);
     574           8 :                                 if (retval) {
     575           8 :                                         result = i_zend_is_true(retval);
     576           8 :                                         zval_ptr_dtor(&retval);
     577             :                                 }
     578             :                         }
     579             :                 } else {
     580           2 :                         result = 0;
     581             :                 }
     582          78 :                 zval_ptr_dtor(&offset);
     583             :         } else {
     584           0 :                 zend_error(E_ERROR, "Cannot use object of type %s as array", ce->name);
     585           0 :                 return 0;
     586             :         }
     587          78 :         return result;
     588             : }
     589             : /* }}} */
     590             : 
     591      179682 : static zval **zend_std_get_property_ptr_ptr(zval *object, zval *member TSRMLS_DC) /* {{{ */
     592             : {
     593             :         zend_object *zobj;
     594             :         zval tmp_member;
     595             :         zval **retval;
     596             :         zend_property_info *property_info;
     597             : 
     598      179682 :         zobj = Z_OBJ_P(object);
     599             : 
     600      179682 :         if (Z_TYPE_P(member) != IS_STRING) {
     601           0 :                 tmp_member = *member;
     602           0 :                 zval_copy_ctor(&tmp_member);
     603           0 :                 convert_to_string(&tmp_member);
     604           0 :                 member = &tmp_member;
     605             :         }
     606             : 
     607             : #if DEBUG_OBJECT_HANDLERS
     608             :         fprintf(stderr, "Ptr object #%d property: %s\n", Z_OBJ_HANDLE_P(object), Z_STRVAL_P(member));
     609             : #endif
     610             : 
     611      179682 :         property_info = zend_get_property_info(zobj->ce, member, (zobj->ce->__get != NULL) TSRMLS_CC);
     612             : 
     613      179681 :         if (!property_info || zend_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &retval) == FAILURE) {
     614             :                 zval *new_zval;
     615             :                 zend_guard *guard;
     616             : 
     617         336 :                 if (!zobj->ce->__get ||
     618          38 :                         zend_get_property_guard(zobj, property_info, member, &guard) != SUCCESS ||
     619          34 :                         (property_info && guard->in_get)) {
     620             :                         /* we don't have access controls - will just add it */
     621         113 :                         new_zval = &EG(uninitialized_zval);
     622             : 
     623             : /*                      zend_error(E_NOTICE, "Undefined property: %s", Z_STRVAL_P(member)); */
     624         113 :                         Z_ADDREF_P(new_zval);
     625         113 :                         zend_hash_quick_update(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, &new_zval, sizeof(zval *), (void **) &retval);
     626             :                 } else {
     627             :                         /* we do have getter - fail and let it try again with usual get/set */
     628          38 :                         retval = NULL;
     629             :                 }
     630             :         }
     631      179681 :         if (member == &tmp_member) {
     632           0 :                 zval_dtor(member);
     633             :         }
     634      179681 :         return retval;
     635             : }
     636             : /* }}} */
     637             : 
     638         158 : static void zend_std_unset_property(zval *object, zval *member TSRMLS_DC) /* {{{ */
     639             : {
     640             :         zend_object *zobj;
     641         158 :         zval *tmp_member = NULL;
     642             :         zend_property_info *property_info;
     643             : 
     644         158 :         zobj = Z_OBJ_P(object);
     645             : 
     646         158 :         if (Z_TYPE_P(member) != IS_STRING) {
     647           1 :                 ALLOC_ZVAL(tmp_member);
     648           1 :                 *tmp_member = *member;
     649           1 :                 INIT_PZVAL(tmp_member);
     650           1 :                 zval_copy_ctor(tmp_member);
     651           1 :                 convert_to_string(tmp_member);
     652           1 :                 member = tmp_member;
     653             :         }
     654             : 
     655         158 :         property_info = zend_get_property_info(zobj->ce, member, (zobj->ce->__unset != NULL) TSRMLS_CC);
     656             : 
     657         157 :         if (!property_info || zend_hash_quick_del(zobj->properties, property_info->name, property_info->name_length+1, property_info->h) == FAILURE) {
     658          17 :                 zend_guard *guard = NULL;
     659             : 
     660          42 :                 if (zobj->ce->__unset &&
     661           9 :                     zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS &&
     662           9 :                     !guard->in_unset) {
     663             :                         /* have unseter - try with it! */
     664           8 :                         Z_ADDREF_P(object);
     665          16 :                         if (PZVAL_IS_REF(object)) {
     666           0 :                                 SEPARATE_ZVAL(&object);
     667             :                         }
     668           8 :                         guard->in_unset = 1; /* prevent circular unsetting */
     669           8 :                         zend_std_call_unsetter(object, member TSRMLS_CC);
     670           7 :                         guard->in_unset = 0;
     671           7 :                         zval_ptr_dtor(&object);
     672           9 :                 } else if (zobj->ce->__unset && guard && guard->in_unset == 1) {
     673           1 :                         if (Z_STRVAL_P(member)[0] == '\0') {
     674           1 :                                 if (Z_STRLEN_P(member) == 0) {
     675           1 :                                         zend_error(E_ERROR, "Cannot access empty property");
     676             :                                 } else {
     677           0 :                                         zend_error(E_ERROR, "Cannot access property started with '\\0'");
     678             :                                 }
     679             :                         }
     680             :                 }
     681             :         }
     682             : 
     683         155 :         if (tmp_member) {
     684           0 :                 zval_ptr_dtor(&tmp_member);
     685             :         }
     686         155 : }
     687             : /* }}} */
     688             : 
     689          27 : static void zend_std_unset_dimension(zval *object, zval *offset TSRMLS_DC) /* {{{ */
     690             : {
     691          27 :         zend_class_entry *ce = Z_OBJCE_P(object);
     692             : 
     693          27 :         if (instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC)) {
     694         102 :                 SEPARATE_ARG_IF_REF(offset);
     695          27 :                 zend_call_method_with_1_params(&object, ce, NULL, "offsetunset", NULL, offset);
     696          27 :                 zval_ptr_dtor(&offset);
     697             :         } else {
     698           0 :                 zend_error(E_ERROR, "Cannot use object of type %s as array", ce->name);
     699             :         }
     700          27 : }
     701             : /* }}} */
     702             : 
     703         430 : ZEND_API void zend_std_call_user_call(INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
     704             : {
     705         430 :         zend_internal_function *func = (zend_internal_function *)EG(current_execute_data)->function_state.function;
     706             :         zval *method_name_ptr, *method_args_ptr;
     707         430 :         zval *method_result_ptr = NULL;
     708         430 :         zend_class_entry *ce = Z_OBJCE_P(this_ptr);
     709             : 
     710         430 :         ALLOC_ZVAL(method_args_ptr);
     711         430 :         INIT_PZVAL(method_args_ptr);
     712         430 :         array_init_size(method_args_ptr, ZEND_NUM_ARGS());
     713             : 
     714         430 :         if (zend_copy_parameters_array(ZEND_NUM_ARGS(), method_args_ptr TSRMLS_CC) == FAILURE) {
     715           0 :                 zval_dtor(method_args_ptr);
     716           0 :                 zend_error(E_ERROR, "Cannot get arguments for __call");
     717           0 :                 RETURN_FALSE;
     718             :         }
     719             : 
     720         430 :         ALLOC_ZVAL(method_name_ptr);
     721         430 :         INIT_PZVAL(method_name_ptr);
     722         430 :         ZVAL_STRING(method_name_ptr, func->function_name, 0); /* no dup - it's a copy */
     723             : 
     724             :         /* __call handler is called with two arguments:
     725             :            method name
     726             :            array of method parameters
     727             : 
     728             :         */
     729         430 :         zend_call_method_with_2_params(&this_ptr, ce, &ce->__call, ZEND_CALL_FUNC_NAME, &method_result_ptr, method_name_ptr, method_args_ptr);
     730             : 
     731         420 :         if (method_result_ptr) {
     732        1229 :                 if (Z_ISREF_P(method_result_ptr) || Z_REFCOUNT_P(method_result_ptr) > 1) {
     733           4 :                         RETVAL_ZVAL(method_result_ptr, 1, 1);
     734             :                 } else {
     735         814 :                         RETVAL_ZVAL(method_result_ptr, 0, 1);
     736             :                 }
     737             :         }
     738             : 
     739             :         /* now destruct all auxiliaries */
     740         420 :         zval_ptr_dtor(&method_args_ptr);
     741         420 :         zval_ptr_dtor(&method_name_ptr);
     742             : 
     743             :         /* destruct the function also, then - we have allocated it in get_method */
     744         420 :         efree(func);
     745             : }
     746             : /* }}} */
     747             : 
     748             : /* Ensures that we're allowed to call a private method.
     749             :  * Returns the function address that should be called, or NULL
     750             :  * if no such function exists.
     751             :  */
     752          86 : static inline zend_function *zend_check_private_int(zend_function *fbc, zend_class_entry *ce, char *function_name_strval, int function_name_strlen TSRMLS_DC) /* {{{ */
     753             : {
     754          86 :         if (!ce) {
     755           6 :                 return 0;
     756             :         }
     757             : 
     758             :         /* We may call a private function if:
     759             :          * 1.  The class of our object is the same as the scope, and the private
     760             :          *     function (EX(fbc)) has the same scope.
     761             :          * 2.  One of our parent classes are the same as the scope, and it contains
     762             :          *     a private function with the same name that has the same scope.
     763             :          */
     764          80 :         if (fbc->common.scope == ce && EG(scope) == ce) {
     765             :                 /* rule #1 checks out ok, allow the function call */
     766          41 :                 return fbc;
     767             :         }
     768             : 
     769             : 
     770             :         /* Check rule #2 */
     771          39 :         ce = ce->parent;
     772          90 :         while (ce) {
     773          23 :                 if (ce == EG(scope)) {
     774          55 :                         if (zend_hash_find(&ce->function_table, function_name_strval, function_name_strlen+1, (void **) &fbc)==SUCCESS
     775          44 :                                 && fbc->op_array.fn_flags & ZEND_ACC_PRIVATE
     776          22 :                                 && fbc->common.scope == EG(scope)) {
     777           9 :                                 return fbc;
     778             :                         }
     779           2 :                         break;
     780             :                 }
     781          12 :                 ce = ce->parent;
     782             :         }
     783          30 :         return NULL;
     784             : }
     785             : /* }}} */
     786             : 
     787          30 : ZEND_API int zend_check_private(zend_function *fbc, zend_class_entry *ce, char *function_name_strval, int function_name_strlen TSRMLS_DC) /* {{{ */
     788             : {
     789          30 :         return zend_check_private_int(fbc, ce, function_name_strval, function_name_strlen TSRMLS_CC) != NULL;
     790             : }
     791             : /* }}} */
     792             : 
     793             : /* Ensures that we're allowed to call a protected method.
     794             :  */
     795        7870 : ZEND_API int zend_check_protected(zend_class_entry *ce, zend_class_entry *scope) /* {{{ */
     796             : {
     797        7870 :         zend_class_entry *fbc_scope = ce;
     798             : 
     799             :         /* Is the context that's calling the function, the same as one of
     800             :          * the function's parents?
     801             :          */
     802       16169 :         while (fbc_scope) {
     803        8046 :                 if (fbc_scope==scope) {
     804        7617 :                         return 1;
     805             :                 }
     806         429 :                 fbc_scope = fbc_scope->parent;
     807             :         }
     808             : 
     809             :         /* Is the function's scope the same as our current object context,
     810             :          * or any of the parents of our context?
     811             :          */
     812         686 :         while (scope) {
     813         323 :                 if (scope==ce) {
     814         143 :                         return 1;
     815             :                 }
     816         180 :                 scope = scope->parent;
     817             :         }
     818         110 :         return 0;
     819             : }
     820             : /* }}} */
     821             : 
     822          83 : static inline zend_class_entry * zend_get_function_root_class(zend_function *fbc) /* {{{ */
     823             : {
     824          83 :         return fbc->common.prototype ? fbc->common.prototype->common.scope : fbc->common.scope;
     825             : }
     826             : /* }}} */
     827             : 
     828         430 : static inline union _zend_function *zend_get_user_call_function(zend_class_entry *ce, const char *method_name, int method_len) /* {{{ */
     829             : {
     830         430 :         zend_internal_function *call_user_call = emalloc(sizeof(zend_internal_function));
     831         430 :         call_user_call->type = ZEND_INTERNAL_FUNCTION;
     832         430 :         call_user_call->module = ce->module;
     833         430 :         call_user_call->handler = zend_std_call_user_call;
     834         430 :         call_user_call->arg_info = NULL;
     835         430 :         call_user_call->num_args = 0;
     836         430 :         call_user_call->scope = ce;
     837         430 :         call_user_call->fn_flags = ZEND_ACC_CALL_VIA_HANDLER;
     838         430 :         call_user_call->function_name = estrndup(method_name, method_len);
     839         430 :         call_user_call->pass_rest_by_reference = 0;
     840         430 :         call_user_call->return_reference = ZEND_RETURN_VALUE;
     841             : 
     842         430 :         return (union _zend_function *)call_user_call;
     843             : }
     844             : /* }}} */
     845             : 
     846      578355 : static union _zend_function *zend_std_get_method(zval **object_ptr, char *method_name, int method_len TSRMLS_DC) /* {{{ */
     847             : {
     848             :         zend_object *zobj;
     849             :         zend_function *fbc;
     850             :         char *lc_method_name;
     851      578355 :         zval *object = *object_ptr;
     852             :         ALLOCA_FLAG(use_heap)
     853             : 
     854      578355 :         lc_method_name = do_alloca(method_len+1, use_heap);
     855             :         /* Create a zend_copy_str_tolower(dest, src, src_length); */
     856      578355 :         zend_str_tolower_copy(lc_method_name, method_name, method_len);
     857             : 
     858      578355 :         zobj = Z_OBJ_P(object);
     859      578355 :         if (zend_hash_find(&zobj->ce->function_table, lc_method_name, method_len+1, (void **)&fbc) == FAILURE) {
     860         694 :                 free_alloca(lc_method_name, use_heap);
     861         694 :                 if (zobj->ce->__call) {
     862         385 :                         return zend_get_user_call_function(zobj->ce, method_name, method_len);
     863             :                 } else {
     864         309 :                         return NULL;
     865             :                 }
     866             :         }
     867             : 
     868             :         /* Check access level */
     869      577661 :         if (fbc->op_array.fn_flags & ZEND_ACC_PRIVATE) {
     870             :                 zend_function *updated_fbc;
     871             : 
     872             :                 /* Ensure that if we're calling a private function, we're allowed to do so.
     873             :                  * If we're not and __call() handler exists, invoke it, otherwise error out.
     874             :                  */
     875          39 :                 updated_fbc = zend_check_private_int(fbc, Z_OBJ_HANDLER_P(object, get_class_entry)(object TSRMLS_CC), lc_method_name, method_len TSRMLS_CC);
     876          39 :                 if (updated_fbc) {
     877          30 :                         fbc = updated_fbc;
     878             :                 } else {
     879           9 :                         if (zobj->ce->__call) {
     880           3 :                                 fbc = zend_get_user_call_function(zobj->ce, method_name, method_len);
     881             :                         } else {
     882           6 :                                 zend_error(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 : "");
     883             :                         }
     884             :                 }
     885             :         } else {
     886             :                 /* Ensure that we haven't overridden a private function and end up calling
     887             :                  * the overriding public function...
     888             :                  */
     889      585827 :                 if (EG(scope) &&
     890        8195 :                     is_derived_class(fbc->common.scope, EG(scope)) &&
     891          10 :                     fbc->op_array.fn_flags & ZEND_ACC_CHANGED) {
     892             :                         zend_function *priv_fbc;
     893             : 
     894          35 :                         if (zend_hash_find(&EG(scope)->function_table, lc_method_name, method_len+1, (void **) &priv_fbc)==SUCCESS
     895          28 :                                 && priv_fbc->common.fn_flags & ZEND_ACC_PRIVATE
     896          14 :                                 && priv_fbc->common.scope == EG(scope)) {
     897           6 :                                 fbc = priv_fbc;
     898             :                         }
     899             :                 }
     900      577622 :                 if ((fbc->common.fn_flags & ZEND_ACC_PROTECTED)) {
     901             :                         /* Ensure that if we're calling a protected function, we're allowed to do so.
     902             :                          * If we're not and __call() handler exists, invoke it, otherwise error out.
     903             :                          */
     904          43 :                         if (!zend_check_protected(zend_get_function_root_class(fbc), EG(scope))) {
     905          12 :                                 if (zobj->ce->__call) {
     906           3 :                                         fbc = zend_get_user_call_function(zobj->ce, method_name, method_len);
     907             :                                 } else {
     908           9 :                                         zend_error(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 : "");
     909             :                                 }
     910             :                         }
     911             :                 }
     912             :         }
     913             : 
     914      577646 :         free_alloca(lc_method_name, use_heap);
     915      577646 :         return fbc;
     916             : }
     917             : /* }}} */
     918             : 
     919          39 : ZEND_API void zend_std_callstatic_user_call(INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
     920             : {
     921          39 :         zend_internal_function *func = (zend_internal_function *)EG(current_execute_data)->function_state.function;
     922             :         zval *method_name_ptr, *method_args_ptr;
     923          39 :         zval *method_result_ptr = NULL;
     924          39 :         zend_class_entry *ce = EG(scope);
     925             : 
     926          39 :         ALLOC_ZVAL(method_args_ptr);
     927          39 :         INIT_PZVAL(method_args_ptr);
     928          39 :         array_init_size(method_args_ptr, ZEND_NUM_ARGS());
     929             : 
     930          39 :         if (zend_copy_parameters_array(ZEND_NUM_ARGS(), method_args_ptr TSRMLS_CC) == FAILURE) {
     931           0 :                 zval_dtor(method_args_ptr);
     932           0 :                 zend_error(E_ERROR, "Cannot get arguments for " ZEND_CALLSTATIC_FUNC_NAME);
     933           0 :                 RETURN_FALSE;
     934             :         }
     935             : 
     936          39 :         ALLOC_ZVAL(method_name_ptr);
     937          39 :         INIT_PZVAL(method_name_ptr);
     938          39 :         ZVAL_STRING(method_name_ptr, func->function_name, 0); /* no dup - it's a copy */
     939             : 
     940             :         /* __callStatic handler is called with two arguments:
     941             :            method name
     942             :            array of method parameters
     943             :         */
     944          39 :         zend_call_method_with_2_params(NULL, ce, &ce->__callstatic, ZEND_CALLSTATIC_FUNC_NAME, &method_result_ptr, method_name_ptr, method_args_ptr);
     945             : 
     946          39 :         if (method_result_ptr) {
     947         114 :                 if (Z_ISREF_P(method_result_ptr) || Z_REFCOUNT_P(method_result_ptr) > 1) {
     948           0 :                         RETVAL_ZVAL(method_result_ptr, 1, 1);
     949             :                 } else {
     950          76 :                         RETVAL_ZVAL(method_result_ptr, 0, 1);
     951             :                 }
     952             :         }
     953             : 
     954             :         /* now destruct all auxiliaries */
     955          39 :         zval_ptr_dtor(&method_args_ptr);
     956          39 :         zval_ptr_dtor(&method_name_ptr);
     957             : 
     958             :         /* destruct the function also, then - we have allocated it in get_method */
     959          39 :         efree(func);
     960             : }
     961             : /* }}} */
     962             : 
     963          39 : static inline union _zend_function *zend_get_user_callstatic_function(zend_class_entry *ce, const char *method_name, int method_len) /* {{{ */
     964             : {
     965          39 :         zend_internal_function *callstatic_user_call = emalloc(sizeof(zend_internal_function));
     966          39 :         callstatic_user_call->type     = ZEND_INTERNAL_FUNCTION;
     967          39 :         callstatic_user_call->module   = ce->module;
     968          39 :         callstatic_user_call->handler  = zend_std_callstatic_user_call;
     969          39 :         callstatic_user_call->arg_info = NULL;
     970          39 :         callstatic_user_call->num_args = 0;
     971          39 :         callstatic_user_call->scope    = ce;
     972          39 :         callstatic_user_call->fn_flags = ZEND_ACC_STATIC | ZEND_ACC_PUBLIC | ZEND_ACC_CALL_VIA_HANDLER;
     973          39 :         callstatic_user_call->function_name = estrndup(method_name, method_len);
     974          39 :         callstatic_user_call->pass_rest_by_reference = 0;
     975          39 :         callstatic_user_call->return_reference       = ZEND_RETURN_VALUE;
     976             : 
     977          39 :         return (zend_function *)callstatic_user_call;
     978             : }
     979             : /* }}} */
     980             : 
     981             : /* This is not (yet?) in the API, but it belongs in the built-in objects callbacks */
     982             : 
     983        7013 : ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, char *function_name_strval, int function_name_strlen TSRMLS_DC) /* {{{ */
     984             : {
     985        7013 :         zend_function *fbc = NULL;
     986        7013 :         char *lc_class_name, *lc_function_name = NULL;
     987             :         
     988        7013 :         lc_function_name = zend_str_tolower_dup(function_name_strval, function_name_strlen);
     989             : 
     990        7013 :         if (function_name_strlen == ce->name_length && ce->constructor) {
     991          44 :                 lc_class_name = zend_str_tolower_dup(ce->name, ce->name_length);
     992             :                 /* Only change the method to the constructor if the constructor isn't called __construct
     993             :                  * we check for __ so we can be binary safe for lowering, we should use ZEND_CONSTRUCTOR_FUNC_NAME
     994             :                  */
     995          44 :                 if (!memcmp(lc_class_name, lc_function_name, function_name_strlen) && memcmp(ce->constructor->common.function_name, "__", sizeof("__") - 1)) {
     996           5 :                         fbc = ce->constructor;
     997             :                 }
     998          44 :                 efree(lc_class_name);
     999             :         }
    1000        7013 :         if (!fbc && zend_hash_find(&ce->function_table, lc_function_name, function_name_strlen+1, (void **) &fbc)==FAILURE) {
    1001          95 :                 efree(lc_function_name);
    1002             : 
    1003         235 :                 if (ce->__call &&
    1004          60 :                     EG(This) &&
    1005          40 :                     Z_OBJ_HT_P(EG(This))->get_class_entry &&
    1006          40 :                     instanceof_function(Z_OBJCE_P(EG(This)), ce TSRMLS_CC)) {
    1007          39 :                         return zend_get_user_call_function(ce, function_name_strval, function_name_strlen);
    1008          56 :                 } else if (ce->__callstatic) {
    1009          37 :                         return zend_get_user_callstatic_function(ce, function_name_strval, function_name_strlen);
    1010             :                 } else {
    1011          19 :                         return NULL;
    1012             :                 }
    1013             :         }
    1014        6918 :         efree(lc_function_name);
    1015             : 
    1016             : #if MBO_0
    1017             :         /* right now this function is used for non static method lookup too */
    1018             :         /* Is the function static */
    1019             :         if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
    1020             :                 zend_error(E_ERROR, "Cannot call non static method %s::%s() without object", ZEND_FN_SCOPE_NAME(fbc), fbc->common.function_name);
    1021             :         }
    1022             : #endif 
    1023        6918 :         if (fbc->op_array.fn_flags & ZEND_ACC_PUBLIC) {
    1024             :                 /* No further checks necessary, most common case */
    1025          51 :         } else if (fbc->op_array.fn_flags & ZEND_ACC_PRIVATE) {
    1026             :                 zend_function *updated_fbc;
    1027             : 
    1028             :                 /* Ensure that if we're calling a private function, we're allowed to do so.
    1029             :                  */
    1030          17 :                 updated_fbc = zend_check_private_int(fbc, EG(scope), function_name_strval, function_name_strlen TSRMLS_CC);
    1031          17 :                 if (updated_fbc) {
    1032          10 :                         fbc = updated_fbc;
    1033             :                 } else {
    1034           7 :                         if (ce->__callstatic) {
    1035           1 :                                 return zend_get_user_callstatic_function(ce, function_name_strval, function_name_strlen);
    1036             :                         }
    1037           6 :                         zend_error(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 : "");
    1038             :                 }
    1039          34 :         } else if ((fbc->common.fn_flags & ZEND_ACC_PROTECTED)) {
    1040             :                 /* Ensure that if we're calling a protected function, we're allowed to do so.
    1041             :                  */
    1042          34 :                 if (!zend_check_protected(zend_get_function_root_class(fbc), EG(scope))) {
    1043           3 :                         if (ce->__callstatic) {
    1044           1 :                                 return zend_get_user_callstatic_function(ce, function_name_strval, function_name_strlen);
    1045             :                         }
    1046           2 :                         zend_error(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 : "");
    1047             :                 }
    1048             :         }
    1049             : 
    1050        6908 :         return fbc;
    1051             : }
    1052             : /* }}} */
    1053             : 
    1054         799 : ZEND_API zval **zend_std_get_static_property(zend_class_entry *ce, char *property_name, int property_name_len, zend_bool silent TSRMLS_DC) /* {{{ */
    1055             : {
    1056         799 :         zval **retval = NULL;
    1057         799 :         zend_class_entry *tmp_ce = ce;
    1058             :         zend_property_info *property_info;
    1059             :         zend_property_info std_property_info;
    1060             : 
    1061         799 :         if (zend_hash_find(&ce->properties_info, property_name, property_name_len+1, (void **) &property_info)==FAILURE) {
    1062          24 :                 std_property_info.flags = ZEND_ACC_PUBLIC;
    1063          24 :                 std_property_info.name = property_name;
    1064          24 :                 std_property_info.name_length = property_name_len;
    1065          24 :                 std_property_info.h = zend_get_hash_value(std_property_info.name, std_property_info.name_length+1);
    1066          24 :                 std_property_info.ce = ce;
    1067          24 :                 property_info = &std_property_info;
    1068             :         }
    1069             : 
    1070             : #if DEBUG_OBJECT_HANDLERS
    1071             :         zend_printf("Access type for %s::%s is %s\n", ce->name, property_name, zend_visibility_string(property_info->flags));
    1072             : #endif
    1073             : 
    1074         799 :         if (!zend_verify_property_access(property_info, ce TSRMLS_CC)) {
    1075          14 :                 if (!silent) {
    1076           2 :                         zend_error(E_ERROR, "Cannot access %s property %s::$%s", zend_visibility_string(property_info->flags), ce->name, property_name);
    1077             :                 }
    1078          12 :                 return NULL;
    1079             :         }
    1080             : 
    1081         785 :         zend_update_class_constants(tmp_ce TSRMLS_CC);
    1082             : 
    1083         785 :         zend_hash_quick_find(CE_STATIC_MEMBERS(tmp_ce), property_info->name, property_info->name_length+1, property_info->h, (void **) &retval);
    1084             : 
    1085         785 :         if (!retval) {
    1086          14 :                 if (silent) {
    1087           5 :                         return NULL;
    1088             :                 } else {
    1089           9 :                         zend_error(E_ERROR, "Access to undeclared static property: %s::$%s", ce->name, property_name);
    1090             :                 }
    1091             :         }
    1092             : 
    1093         771 :         return retval;
    1094             : }
    1095             : /* }}} */
    1096             : 
    1097           0 : ZEND_API zend_bool zend_std_unset_static_property(zend_class_entry *ce, char *property_name, int property_name_len TSRMLS_DC) /* {{{ */
    1098             : {
    1099           0 :         zend_error(E_ERROR, "Attempt to unset static property %s::$%s", ce->name, property_name);
    1100           0 :         return 0;
    1101             : }
    1102             : /* }}} */
    1103             : 
    1104      448286 : ZEND_API union _zend_function *zend_std_get_constructor(zval *object TSRMLS_DC) /* {{{ */
    1105             : {
    1106      448286 :         zend_object *zobj = Z_OBJ_P(object);
    1107      448286 :         zend_function *constructor = zobj->ce->constructor;
    1108             : 
    1109      448286 :         if (constructor) {
    1110      275265 :                 if (constructor->op_array.fn_flags & ZEND_ACC_PUBLIC) {
    1111             :                         /* No further checks necessary */
    1112          17 :                 } else if (constructor->op_array.fn_flags & ZEND_ACC_PRIVATE) {
    1113             :                         /* Ensure that if we're calling a private function, we're allowed to do so.
    1114             :                          */
    1115          11 :                         if (constructor->common.scope != EG(scope)) {
    1116           4 :                                 if (EG(scope)) {
    1117           1 :                                         zend_error(E_ERROR, "Call to private %s::%s() from context '%s'", constructor->common.scope->name, constructor->common.function_name, EG(scope)->name);
    1118             :                                 } else {
    1119           3 :                                         zend_error(E_ERROR, "Call to private %s::%s() from invalid context", constructor->common.scope->name, constructor->common.function_name);
    1120             :                                 }
    1121             :                         }
    1122           6 :                 } else if ((constructor->common.fn_flags & ZEND_ACC_PROTECTED)) {
    1123             :                         /* Ensure that if we're calling a protected function, we're allowed to do so.
    1124             :                          * Constructors only have prototype if they are defined by an interface but
    1125             :                          * it is the compilers responsibility to take care of the prototype.
    1126             :                          */
    1127           6 :                         if (!zend_check_protected(zend_get_function_root_class(constructor), EG(scope))) {
    1128           2 :                                 if (EG(scope)) {
    1129           1 :                                         zend_error(E_ERROR, "Call to protected %s::%s() from context '%s'", constructor->common.scope->name, constructor->common.function_name, EG(scope)->name);
    1130             :                                 } else {
    1131           1 :                                         zend_error(E_ERROR, "Call to protected %s::%s() from invalid context", constructor->common.scope->name, constructor->common.function_name);
    1132             :                                 }
    1133             :                         }
    1134             :                 }
    1135             :         }
    1136             : 
    1137      448280 :         return constructor;
    1138             : }
    1139             : /* }}} */
    1140             : 
    1141             : int zend_compare_symbol_tables_i(HashTable *ht1, HashTable *ht2 TSRMLS_DC);
    1142             : 
    1143         525 : static int zend_std_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
    1144             : {
    1145             :         zend_object *zobj1, *zobj2;
    1146             : 
    1147         525 :         zobj1 = Z_OBJ_P(o1);
    1148         525 :         zobj2 = Z_OBJ_P(o2);
    1149             : 
    1150         525 :         if (zobj1->ce != zobj2->ce) {
    1151          34 :                 return 1; /* different classes */
    1152             :         }
    1153         491 :         return zend_compare_symbol_tables_i(zobj1->properties, zobj2->properties TSRMLS_CC);
    1154             : }
    1155             : /* }}} */
    1156             : 
    1157         296 : static int zend_std_has_property(zval *object, zval *member, int has_set_exists TSRMLS_DC) /* {{{ */
    1158             : {
    1159             :         zend_object *zobj;
    1160             :         int result;
    1161             :         zval **value;
    1162         296 :         zval *tmp_member = NULL;
    1163             :         zend_property_info *property_info;
    1164             : 
    1165         296 :         zobj = Z_OBJ_P(object);
    1166             : 
    1167         296 :         if (Z_TYPE_P(member) != IS_STRING) {
    1168           4 :                 ALLOC_ZVAL(tmp_member);
    1169           4 :                 *tmp_member = *member;
    1170           4 :                 INIT_PZVAL(tmp_member);
    1171           4 :                 zval_copy_ctor(tmp_member);
    1172           4 :                 convert_to_string(tmp_member);
    1173           4 :                 member = tmp_member;
    1174             :         }
    1175             : 
    1176             : #if DEBUG_OBJECT_HANDLERS
    1177             :         fprintf(stderr, "Read object #%d property: %s\n", Z_OBJ_HANDLE_P(object), Z_STRVAL_P(member));
    1178             : #endif
    1179             : 
    1180         296 :         property_info = zend_get_property_info(zobj->ce, member, 1 TSRMLS_CC);
    1181             : 
    1182         432 :         if (!property_info || zend_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &value) == FAILURE) {
    1183             :                 zend_guard *guard;
    1184             : 
    1185         136 :                 result = 0;
    1186         212 :                 if ((has_set_exists != 2) &&
    1187          46 :                     zobj->ce->__isset &&
    1188          15 :                     zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS &&
    1189          15 :                     !guard->in_isset) {
    1190             :                         zval *rv;
    1191             : 
    1192             :                         /* have issetter - try with it! */
    1193          11 :                         Z_ADDREF_P(object);
    1194          22 :                         if (PZVAL_IS_REF(object)) {
    1195           0 :                                 SEPARATE_ZVAL(&object);
    1196             :                         }
    1197          11 :                         guard->in_isset = 1; /* prevent circular getting */
    1198          11 :                         rv = zend_std_call_issetter(object, member TSRMLS_CC);
    1199          11 :                         if (rv) {
    1200          11 :                                 result = zend_is_true(rv);
    1201          11 :                                 zval_ptr_dtor(&rv);
    1202          11 :                                 if (has_set_exists && result) {
    1203           3 :                                         if (!EG(exception) && zobj->ce->__get && !guard->in_get) {
    1204           1 :                                                 guard->in_get = 1;
    1205           1 :                                                 rv = zend_std_call_getter(object, member TSRMLS_CC);
    1206           1 :                                                 guard->in_get = 0;
    1207           1 :                                                 if (rv) {
    1208           1 :                                                         Z_ADDREF_P(rv);
    1209           1 :                                                         result = i_zend_is_true(rv);
    1210           1 :                                                         zval_ptr_dtor(&rv);
    1211             :                                                 } else {
    1212           0 :                                                         result = 0;
    1213             :                                                 }
    1214             :                                         } else {
    1215           1 :                                                 result = 0;
    1216             :                                         }
    1217             :                                 }
    1218             :                         }
    1219          11 :                         guard->in_isset = 0;
    1220          11 :                         zval_ptr_dtor(&object);
    1221             :                 }
    1222             :         } else {
    1223         160 :                 switch (has_set_exists) {
    1224             :                 case 0:
    1225         106 :                         result = (Z_TYPE_PP(value) != IS_NULL);
    1226         106 :                         break;
    1227             :                 default:
    1228          23 :                         result = zend_is_true(*value);
    1229          23 :                         break;
    1230             :                 case 2:
    1231          31 :                         result = 1;
    1232             :                         break;
    1233             :                 }
    1234             :         }
    1235             : 
    1236         296 :         if (tmp_member) {
    1237           4 :                 zval_ptr_dtor(&tmp_member);
    1238             :         }
    1239         296 :         return result;
    1240             : }
    1241             : /* }}} */
    1242             : 
    1243     3466005 : zend_class_entry *zend_std_object_get_class(const zval *object TSRMLS_DC) /* {{{ */
    1244             : {
    1245             :         zend_object *zobj;
    1246     3466005 :         zobj = Z_OBJ_P(object);
    1247             : 
    1248     3466005 :         return zobj->ce;
    1249             : }
    1250             : /* }}} */
    1251             : 
    1252      137190 : int zend_std_object_get_class_name(const zval *object, char **class_name, zend_uint *class_name_len, int parent TSRMLS_DC) /* {{{ */
    1253             : {
    1254             :         zend_object *zobj;
    1255             :         zend_class_entry *ce;
    1256      137190 :         zobj = Z_OBJ_P(object);
    1257             : 
    1258      137190 :         if (parent) {
    1259          11 :                 if (!zobj->ce->parent) {
    1260           8 :                         return FAILURE;
    1261             :                 }
    1262           3 :                 ce = zobj->ce->parent;
    1263             :         } else {
    1264      137179 :                 ce = zobj->ce;
    1265             :         }
    1266             : 
    1267      137182 :         *class_name_len = ce->name_length;
    1268      137182 :         *class_name = estrndup(ce->name, ce->name_length);
    1269      137182 :         return SUCCESS;
    1270             : }
    1271             : /* }}} */
    1272             : 
    1273      267111 : ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int type TSRMLS_DC) /* {{{ */
    1274             : {
    1275             :         zval *retval;
    1276             :         zend_class_entry *ce;
    1277             : 
    1278      267111 :         switch (type) {
    1279             :                 case IS_STRING:
    1280      104251 :                         ce = Z_OBJCE_P(readobj);
    1281      207791 :                         if (ce->__tostring &&
    1282      103540 :                                 (zend_call_method_with_0_params(&readobj, ce, &ce->__tostring, "__tostring", &retval) || EG(exception))) {
    1283      103536 :                                 if (EG(exception)) {
    1284           4 :                                         if (retval) {
    1285           0 :                                                 zval_ptr_dtor(&retval);
    1286             :                                         }
    1287           4 :                                         EG(exception) = NULL;
    1288           4 :                                         zend_error(E_ERROR, "Method %s::__toString() must not throw an exception", ce->name);
    1289           0 :                                         return FAILURE;
    1290             :                                 }
    1291      103532 :                                 if (Z_TYPE_P(retval) == IS_STRING) {
    1292      103528 :                                         INIT_PZVAL(writeobj);
    1293      103528 :                                         if (readobj == writeobj) {
    1294           0 :                                                 zval_dtor(readobj);
    1295             :                                         }
    1296      207056 :                                         ZVAL_ZVAL(writeobj, retval, 1, 1);
    1297      103528 :                                         if (Z_TYPE_P(writeobj) != type) {
    1298           0 :                                                 convert_to_explicit_type(writeobj, type);
    1299             :                                         }
    1300      103528 :                                         return SUCCESS;
    1301             :                                 } else {
    1302           4 :                                         zval_ptr_dtor(&retval);
    1303           4 :                                         INIT_PZVAL(writeobj);
    1304           4 :                                         if (readobj == writeobj) {
    1305           0 :                                                 zval_dtor(readobj);
    1306             :                                         }
    1307           4 :                                         ZVAL_EMPTY_STRING(writeobj);
    1308           4 :                                         zend_error(E_RECOVERABLE_ERROR, "Method %s::__toString() must return a string value", ce->name);
    1309           4 :                                         return SUCCESS;
    1310             :                                 }
    1311             :                         }
    1312         715 :                         return FAILURE;
    1313             :                 case IS_BOOL:
    1314      162609 :                         INIT_PZVAL(writeobj);
    1315      162609 :                         ZVAL_BOOL(writeobj, 1);
    1316      162609 :                         return SUCCESS;
    1317             :                 case IS_LONG:
    1318         143 :                         ce = Z_OBJCE_P(readobj);
    1319         143 :                         zend_error(E_NOTICE, "Object of class %s could not be converted to int", ce->name);
    1320         143 :                         INIT_PZVAL(writeobj);
    1321         143 :                         if (readobj == writeobj) {
    1322           0 :                                 zval_dtor(readobj);
    1323             :                         }
    1324         143 :                         ZVAL_LONG(writeobj, 1);
    1325         143 :                         return SUCCESS;
    1326             :                 case IS_DOUBLE:
    1327          43 :                         ce = Z_OBJCE_P(readobj);
    1328          43 :                         zend_error(E_NOTICE, "Object of class %s could not be converted to double", ce->name);
    1329          43 :                         INIT_PZVAL(writeobj);
    1330          43 :                         if (readobj == writeobj) {
    1331           0 :                                 zval_dtor(readobj);
    1332             :                         }
    1333          43 :                         ZVAL_DOUBLE(writeobj, 1);
    1334          43 :                         return SUCCESS;
    1335             :                 default:
    1336          65 :                         INIT_PZVAL(writeobj);
    1337          65 :                         Z_TYPE_P(writeobj) = IS_NULL;
    1338             :                         break;
    1339             :         }
    1340          65 :         return FAILURE;
    1341             : }
    1342             : /* }}} */
    1343             : 
    1344          71 : int zend_std_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zval **zobj_ptr TSRMLS_DC) /* {{{ */
    1345             : {
    1346             :         zend_class_entry *ce;
    1347          71 :         if (Z_TYPE_P(obj) != IS_OBJECT) {
    1348           0 :                 return FAILURE;
    1349             :         }
    1350             : 
    1351          71 :         ce = Z_OBJCE_P(obj);
    1352             : 
    1353          71 :         if (zend_hash_find(&ce->function_table, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME), (void**)fptr_ptr) == FAILURE) {
    1354          52 :                 return FAILURE;
    1355             :         }
    1356             : 
    1357          19 :         *ce_ptr = ce;
    1358          19 :         if ((*fptr_ptr)->common.fn_flags & ZEND_ACC_STATIC) {
    1359           0 :                 if (zobj_ptr) {
    1360           0 :                         *zobj_ptr = NULL;
    1361             :                 }
    1362             :         } else {
    1363          19 :                 if (zobj_ptr) {
    1364          19 :                         *zobj_ptr = obj;
    1365             :                 }
    1366             :         }
    1367          19 :         return SUCCESS;
    1368             : }
    1369             : /* }}} */
    1370             : 
    1371             : ZEND_API zend_object_handlers std_object_handlers = {
    1372             :         zend_objects_store_add_ref,                             /* add_ref */
    1373             :         zend_objects_store_del_ref,                             /* del_ref */
    1374             :         zend_objects_clone_obj,                                 /* clone_obj */
    1375             : 
    1376             :         zend_std_read_property,                                 /* read_property */
    1377             :         zend_std_write_property,                                /* write_property */
    1378             :         zend_std_read_dimension,                                /* read_dimension */
    1379             :         zend_std_write_dimension,                               /* write_dimension */
    1380             :         zend_std_get_property_ptr_ptr,                  /* get_property_ptr_ptr */
    1381             :         NULL,                                                                   /* get */
    1382             :         NULL,                                                                   /* set */
    1383             :         zend_std_has_property,                                  /* has_property */
    1384             :         zend_std_unset_property,                                /* unset_property */
    1385             :         zend_std_has_dimension,                                 /* has_dimension */
    1386             :         zend_std_unset_dimension,                               /* unset_dimension */
    1387             :         zend_std_get_properties,                                /* get_properties */
    1388             :         zend_std_get_method,                                    /* get_method */
    1389             :         NULL,                                                                   /* call_method */
    1390             :         zend_std_get_constructor,                               /* get_constructor */
    1391             :         zend_std_object_get_class,                              /* get_class_entry */
    1392             :         zend_std_object_get_class_name,                 /* get_class_name */
    1393             :         zend_std_compare_objects,                               /* compare_objects */
    1394             :         zend_std_cast_object_tostring,                  /* cast_object */
    1395             :         NULL,                                                                   /* count_elements */
    1396             :         NULL,                                                                   /* get_debug_info */
    1397             :         zend_std_get_closure,                                   /* get_closure */
    1398             : };
    1399             : 
    1400             : /*
    1401             :  * Local variables:
    1402             :  * tab-width: 4
    1403             :  * c-basic-offset: 4
    1404             :  * indent-tabs-mode: t
    1405             :  * End:
    1406             :  */

Generated by: LCOV version 1.10

Generated at Sun, 27 Jul 2014 12:58:24 +0000 (2 days ago)

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