PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LTP GCOV extension - code coverage report
Current view: directory - var/php_gcov/PHP_5_3/Zend - zend_object_handlers.c
Test: PHP Code Coverage
Date: 2009-11-21 Instrumented lines: 605
Code covered: 92.9 % Executed lines: 562
Legend: not executed executed

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

Generated by: LTP GCOV extension version 1.5

Generated at Sat, 21 Nov 2009 12:26:54 +0000 (3 days ago)

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