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

LCOV - code coverage report
Current view: top level - Zend - zend_interfaces.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 220 232 94.8 %
Date: 2015-05-21 Functions: 21 21 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2015 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Marcus Boerger <helly@php.net>                              |
      16             :    +----------------------------------------------------------------------+
      17             : */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : #include "zend.h"
      22             : #include "zend_API.h"
      23             : #include "zend_interfaces.h"
      24             : #include "zend_exceptions.h"
      25             : 
      26             : ZEND_API zend_class_entry *zend_ce_traversable;
      27             : ZEND_API zend_class_entry *zend_ce_aggregate;
      28             : ZEND_API zend_class_entry *zend_ce_iterator;
      29             : ZEND_API zend_class_entry *zend_ce_arrayaccess;
      30             : ZEND_API zend_class_entry *zend_ce_serializable;
      31             : 
      32             : /* {{{ zend_call_method
      33             :  Only returns the returned zval if retval_ptr != NULL */
      34      455268 : ZEND_API zval* zend_call_method(zval *object, zend_class_entry *obj_ce, zend_function **fn_proxy, const char *function_name, size_t function_name_len, zval *retval_ptr, int param_count, zval* arg1, zval* arg2)
      35             : {
      36             :         int result;
      37             :         zend_fcall_info fci;
      38             :         zval retval;
      39             :         HashTable *function_table;
      40             : 
      41             :         zval params[2];
      42             : 
      43      455268 :         if (param_count > 0) {
      44        5190 :                 ZVAL_COPY_VALUE(&params[0], arg1);
      45             :         }
      46      455268 :         if (param_count > 1) {
      47        2352 :                 ZVAL_COPY_VALUE(&params[1], arg2);
      48             :         }
      49             : 
      50      455268 :         fci.size = sizeof(fci);
      51             :         /*fci.function_table = NULL; will be read form zend_class_entry of object if needed */
      52      910478 :         fci.object = (object && Z_TYPE_P(object) == IS_OBJECT) ? Z_OBJ_P(object) : NULL;
      53      910536 :         ZVAL_STRINGL(&fci.function_name, function_name, function_name_len);
      54      455268 :         fci.retval = retval_ptr ? retval_ptr : &retval;
      55      455268 :         fci.param_count = param_count;
      56      455268 :         fci.params = params;
      57      455268 :         fci.no_separation = 1;
      58      455268 :         fci.symbol_table = NULL;
      59             : 
      60      455306 :         if (!fn_proxy && !obj_ce) {
      61             :                 /* no interest in caching and no information already present that is
      62             :                  * needed later inside zend_call_function. */
      63          38 :                 fci.function_table = !object ? EG(function_table) : NULL;
      64          38 :                 result = zend_call_function(&fci, NULL);
      65          38 :                 zval_ptr_dtor(&fci.function_name);
      66             :         } else {
      67             :                 zend_fcall_info_cache fcic;
      68             : 
      69      455230 :                 fcic.initialized = 1;
      70      455230 :                 if (!obj_ce) {
      71          47 :                         obj_ce = object ? Z_OBJCE_P(object) : NULL;
      72             :                 }
      73      455230 :                 if (obj_ce) {
      74      455183 :                         function_table = &obj_ce->function_table;
      75             :                 } else {
      76          47 :                         function_table = EG(function_table);
      77             :                 }
      78      467187 :                 if (!fn_proxy || !*fn_proxy) {
      79       23914 :                         if ((fcic.function_handler = zend_hash_find_ptr(function_table, Z_STR(fci.function_name))) == NULL) {
      80             :                                 /* error at c-level */
      81           0 :                                 zend_error_noreturn(E_CORE_ERROR, "Couldn't find implementation for method %s%s%s", obj_ce ? obj_ce->name->val : "", obj_ce ? "::" : "", function_name);
      82             :                         }
      83       11957 :                         if (fn_proxy) {
      84        1085 :                                 *fn_proxy = fcic.function_handler;
      85             :                         }
      86             :                 } else {
      87      443273 :                         fcic.function_handler = *fn_proxy;
      88             :                 }
      89      455230 :                 fcic.calling_scope = obj_ce;
      90      455230 :                 if (object) {
      91      455172 :                         fcic.called_scope = Z_OBJCE_P(object);
      92             :                 } else {
      93          58 :                         zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data));
      94             : 
      95          69 :                         if (obj_ce &&
      96             :                             (!called_scope ||
      97           0 :                              !instanceof_function(called_scope, obj_ce))) {
      98          11 :                                 fcic.called_scope = obj_ce;
      99             :                         } else {
     100          47 :                                 fcic.called_scope = called_scope;
     101             :                         }
     102             :                 }
     103      455230 :                 fcic.object = object ? Z_OBJ_P(object) : NULL;
     104      455230 :                 result = zend_call_function(&fci, &fcic);
     105      455225 :                 zval_ptr_dtor(&fci.function_name);
     106             :         }
     107      455263 :         if (result == FAILURE) {
     108             :                 /* error at c-level */
     109           3 :                 if (!obj_ce) {
     110           1 :                         obj_ce = object ? Z_OBJCE_P(object) : NULL;
     111             :                 }
     112           3 :                 if (!EG(exception)) {
     113           0 :                         zend_error_noreturn(E_CORE_ERROR, "Couldn't execute method %s%s%s", obj_ce ? obj_ce->name->val : "", obj_ce ? "::" : "", function_name);
     114             :                 }
     115             :         }
     116             :         /* copy arguments back, they might be changed by references */
     117      460453 :         if (param_count > 0 && Z_ISREF(params[0]) && !Z_ISREF_P(arg1)) {
     118           0 :                 ZVAL_COPY_VALUE(arg1, &params[0]);
     119             :         }
     120      457615 :         if (param_count > 1 && Z_ISREF(params[1]) && !Z_ISREF_P(arg2)) {
     121           0 :                 ZVAL_COPY_VALUE(arg2, &params[1]);
     122             :         }
     123      455263 :         if (!retval_ptr) {
     124      111683 :                 zval_ptr_dtor(&retval);
     125      111683 :                 return NULL;
     126             :         }
     127      343580 :         return retval_ptr;
     128             : }
     129             : /* }}} */
     130             : 
     131             : /* iterator interface, c-level functions used by engine */
     132             : 
     133             : /* {{{ zend_user_it_new_iterator */
     134          84 : ZEND_API void zend_user_it_new_iterator(zend_class_entry *ce, zval *object, zval *retval)
     135             : {
     136          84 :         zend_call_method_with_0_params(object, ce, &ce->iterator_funcs.zf_new_iterator, "getiterator", retval);
     137          84 : }
     138             : /* }}} */
     139             : 
     140             : /* {{{ zend_user_it_invalidate_current */
     141       13029 : ZEND_API void zend_user_it_invalidate_current(zend_object_iterator *_iter)
     142             : {
     143       13029 :         zend_user_iterator *iter = (zend_user_iterator*)_iter;
     144             : 
     145       26058 :         if (!Z_ISUNDEF(iter->value)) {
     146        9113 :                 zval_ptr_dtor(&iter->value);
     147        9113 :                 ZVAL_UNDEF(&iter->value);
     148             :         }
     149       13029 : }
     150             : /* }}} */
     151             : 
     152             : /* {{{ zend_user_it_dtor */
     153         573 : static void zend_user_it_dtor(zend_object_iterator *_iter)
     154             : {
     155         573 :         zend_user_iterator *iter = (zend_user_iterator*)_iter;
     156         573 :         zval *object = &iter->it.data;
     157             : 
     158         573 :         zend_user_it_invalidate_current(_iter);
     159         573 :         zval_ptr_dtor(object);
     160         573 : }
     161             : /* }}} */
     162             : 
     163             : /* {{{ zend_user_it_valid */
     164       12786 : ZEND_API int zend_user_it_valid(zend_object_iterator *_iter)
     165             : {
     166       12786 :         if (_iter) {
     167       12786 :                 zend_user_iterator *iter = (zend_user_iterator*)_iter;
     168       12786 :                 zval *object = &iter->it.data;
     169             :                 zval more;
     170             :                 int result;
     171             : 
     172       12786 :                 zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs.zf_valid, "valid", &more);
     173       12786 :                 if (Z_TYPE(more) != IS_UNDEF) {
     174       12773 :                         result = i_zend_is_true(&more);
     175       12773 :                         zval_ptr_dtor(&more);
     176       12773 :                         return result ? SUCCESS : FAILURE;
     177             :                 }
     178             :         }
     179          13 :         return FAILURE;
     180             : }
     181             : /* }}} */
     182             : 
     183             : /* {{{ zend_user_it_get_current_data */
     184        9162 : ZEND_API zval *zend_user_it_get_current_data(zend_object_iterator *_iter)
     185             : {
     186        9162 :         zend_user_iterator *iter = (zend_user_iterator*)_iter;
     187        9162 :         zval *object = &iter->it.data;
     188             : 
     189       18324 :         if (Z_ISUNDEF(iter->value)) {
     190        9125 :                 zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs.zf_current, "current", &iter->value);
     191             :         }
     192        9162 :         return &iter->value;
     193             : }
     194             : /* }}} */
     195             : 
     196             : /* {{{ zend_user_it_get_current_key_default */
     197             : #if 0
     198             : static int zend_user_it_get_current_key_default(zend_object_iterator *_iter, char **str_key, uint *str_key_len, ulong *int_key)
     199             : {
     200             :         *int_key = _iter->index;
     201             :         return HASH_KEY_IS_LONG;
     202             : }
     203             : #endif
     204             : /* }}} */
     205             : 
     206             : /* {{{ zend_user_it_get_current_key */
     207        7520 : ZEND_API void zend_user_it_get_current_key(zend_object_iterator *_iter, zval *key)
     208             : {
     209        7520 :         zend_user_iterator *iter = (zend_user_iterator*)_iter;
     210        7520 :         zval *object = &iter->it.data;
     211             :         zval retval;
     212             : 
     213        7520 :         zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs.zf_key, "key", &retval);
     214             : 
     215        7520 :         if (Z_TYPE(retval) != IS_UNDEF) {
     216       22530 :                 ZVAL_ZVAL(key, &retval, 1, 1);
     217             :         } else {
     218          10 :                 if (!EG(exception)) {
     219           0 :                         zend_error(E_WARNING, "Nothing returned from %s::key()", iter->ce->name->val);
     220             :                 }
     221             : 
     222          10 :                 ZVAL_LONG(key, 0);
     223             :         }
     224        7520 : }
     225             : /* }}} */
     226             : 
     227             : /* {{{ zend_user_it_move_forward */
     228        9213 : ZEND_API void zend_user_it_move_forward(zend_object_iterator *_iter)
     229             : {
     230        9213 :         zend_user_iterator *iter = (zend_user_iterator*)_iter;
     231        9213 :         zval *object = &iter->it.data;
     232             : 
     233        9213 :         zend_user_it_invalidate_current(_iter);
     234        9213 :         zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs.zf_next, "next", NULL);
     235        9213 : }
     236             : /* }}} */
     237             : 
     238             : /* {{{ zend_user_it_rewind */
     239         657 : ZEND_API void zend_user_it_rewind(zend_object_iterator *_iter)
     240             : {
     241         657 :         zend_user_iterator *iter = (zend_user_iterator*)_iter;
     242         657 :         zval *object = &iter->it.data;
     243             : 
     244         657 :         zend_user_it_invalidate_current(_iter);
     245         657 :         zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs.zf_rewind, "rewind", NULL);
     246         657 : }
     247             : /* }}} */
     248             : 
     249             : zend_object_iterator_funcs zend_interface_iterator_funcs_iterator = {
     250             :         zend_user_it_dtor,
     251             :         zend_user_it_valid,
     252             :         zend_user_it_get_current_data,
     253             :         zend_user_it_get_current_key,
     254             :         zend_user_it_move_forward,
     255             :         zend_user_it_rewind,
     256             :         zend_user_it_invalidate_current
     257             : };
     258             : 
     259             : /* {{{ zend_user_it_get_iterator */
     260         575 : static zend_object_iterator *zend_user_it_get_iterator(zend_class_entry *ce, zval *object, int by_ref)
     261             : {
     262             :         zend_user_iterator *iterator;
     263             : 
     264         575 :         if (by_ref) {
     265           2 :                 zend_error(E_EXCEPTION | E_ERROR, "An iterator cannot be used with foreach by reference");
     266           2 :                 return NULL;
     267             :         }
     268             : 
     269         573 :         iterator = emalloc(sizeof(zend_user_iterator));
     270             : 
     271         573 :         zend_iterator_init((zend_object_iterator*)iterator);
     272             : 
     273         573 :         ZVAL_COPY(&iterator->it.data, object);
     274         573 :         iterator->it.funcs = ce->iterator_funcs.funcs;
     275         573 :         iterator->ce = Z_OBJCE_P(object);
     276         573 :         ZVAL_UNDEF(&iterator->value);
     277         573 :         return (zend_object_iterator*)iterator;
     278             : }
     279             : /* }}} */
     280             : 
     281             : /* {{{ zend_user_it_get_new_iterator */
     282          84 : ZEND_API zend_object_iterator *zend_user_it_get_new_iterator(zend_class_entry *ce, zval *object, int by_ref)
     283             : {
     284             :         zval iterator;
     285             :         zend_object_iterator *new_iterator;
     286             :         zend_class_entry *ce_it;
     287             : 
     288          84 :         zend_user_it_new_iterator(ce, object, &iterator);
     289          84 :         ce_it = (Z_TYPE(iterator) == IS_OBJECT) ? Z_OBJCE(iterator) : NULL;
     290             : 
     291          84 :         if (!ce_it || !ce_it->get_iterator || (ce_it->get_iterator == zend_user_it_get_new_iterator && Z_OBJ(iterator) == Z_OBJ_P(object))) {
     292           8 :                 if (!EG(exception)) {
     293           5 :                         zend_throw_exception_ex(NULL, 0, "Objects returned by %s::getIterator() must be traversable or implement interface Iterator", ce ? ce->name->val : Z_OBJCE_P(object)->name->val);
     294             :                 }
     295           8 :                 zval_ptr_dtor(&iterator);
     296           8 :                 return NULL;
     297             :         }
     298             : 
     299          76 :         new_iterator = ce_it->get_iterator(ce_it, &iterator, by_ref);
     300          76 :         zval_ptr_dtor(&iterator);
     301          76 :         return new_iterator;
     302             : }
     303             : /* }}} */
     304             : 
     305             : /* {{{ zend_implement_traversable */
     306     1087949 : static int zend_implement_traversable(zend_class_entry *interface, zend_class_entry *class_type)
     307             : {
     308             :         /* check that class_type is traversable at c-level or implements at least one of 'aggregate' and 'Iterator' */
     309             :         uint32_t i;
     310             : 
     311     1087949 :         if (class_type->get_iterator || (class_type->parent && class_type->parent->get_iterator)) {
     312     1067031 :                 return SUCCESS;
     313             :         }
     314       62753 :         for (i = 0; i < class_type->num_interfaces; i++) {
     315       62752 :                 if (class_type->interfaces[i] == zend_ce_aggregate || class_type->interfaces[i] == zend_ce_iterator) {
     316       20917 :                         return SUCCESS;
     317             :                 }
     318             :         }
     319           4 :         zend_error_noreturn(E_CORE_ERROR, "Class %s must implement interface %s as part of either %s or %s",
     320           1 :                 class_type->name->val,
     321           1 :                 zend_ce_traversable->name->val,
     322           1 :                 zend_ce_iterator->name->val,
     323           1 :                 zend_ce_aggregate->name->val);
     324             :         return FAILURE;
     325             : }
     326             : /* }}} */
     327             : 
     328             : /* {{{ zend_implement_aggregate */
     329       20987 : static int zend_implement_aggregate(zend_class_entry *interface, zend_class_entry *class_type)
     330             : {
     331             :         uint32_t i;
     332       20987 :         int t = -1;
     333             : 
     334       20987 :         if (class_type->get_iterator) {
     335           6 :                 if (class_type->type == ZEND_INTERNAL_CLASS) {
     336             :                         /* inheritance ensures the class has necessary userland methods */
     337           0 :                         return SUCCESS;
     338           6 :                 } else if (class_type->get_iterator != zend_user_it_get_new_iterator) {
     339             :                         /* c-level get_iterator cannot be changed (exception being only Traversable is implmented) */
     340           6 :                         if (class_type->num_interfaces) {
     341          16 :                                 for (i = 0; i < class_type->num_interfaces; i++) {
     342          11 :                                         if (class_type->interfaces[i] == zend_ce_iterator) {
     343           3 :                                                 zend_error_noreturn(E_ERROR, "Class %s cannot implement both %s and %s at the same time",
     344           1 :                                                                         class_type->name->val,
     345           1 :                                                                         interface->name->val,
     346           1 :                                                                         zend_ce_iterator->name->val);
     347             :                                                 return FAILURE;
     348             :                                         }
     349          10 :                                         if (class_type->interfaces[i] == zend_ce_traversable) {
     350           5 :                                                 t = i;
     351             :                                         }
     352             :                                 }
     353             :                         }
     354           5 :                         if (t == -1) {
     355           0 :                                 return FAILURE;
     356             :                         }
     357             :                 }
     358             :         }
     359       20986 :         class_type->iterator_funcs.zf_new_iterator = NULL;
     360       20986 :         class_type->get_iterator = zend_user_it_get_new_iterator;
     361       20986 :         return SUCCESS;
     362             : }
     363             : /* }}} */
     364             : 
     365             : /* {{{ zend_implement_iterator */
     366      857760 : static int zend_implement_iterator(zend_class_entry *interface, zend_class_entry *class_type)
     367             : {
     368      857760 :         if (class_type->get_iterator && class_type->get_iterator != zend_user_it_get_iterator) {
     369       41833 :                 if (class_type->type == ZEND_INTERNAL_CLASS) {
     370             :                         /* inheritance ensures the class has the necessary userland methods */
     371       41832 :                         return SUCCESS;
     372             :                 } else {
     373             :                         /* c-level get_iterator cannot be changed */
     374           1 :                         if (class_type->get_iterator == zend_user_it_get_new_iterator) {
     375           3 :                                 zend_error_noreturn(E_ERROR, "Class %s cannot implement both %s and %s at the same time",
     376           1 :                                                         class_type->name->val,
     377           1 :                                                         interface->name->val,
     378           1 :                                                         zend_ce_aggregate->name->val);
     379             :                         }
     380           0 :                         return FAILURE;
     381             :                 }
     382             :         }
     383      815927 :         class_type->get_iterator = zend_user_it_get_iterator;
     384      815927 :         class_type->iterator_funcs.zf_valid = NULL;
     385      815927 :         class_type->iterator_funcs.zf_current = NULL;
     386      815927 :         class_type->iterator_funcs.zf_key = NULL;
     387      815927 :         class_type->iterator_funcs.zf_next = NULL;
     388      815927 :         class_type->iterator_funcs.zf_rewind = NULL;
     389      815927 :         if (!class_type->iterator_funcs.funcs) {
     390      815927 :                 class_type->iterator_funcs.funcs = &zend_interface_iterator_funcs_iterator;
     391             :         }
     392      815927 :         return SUCCESS;
     393             : }
     394             : /* }}} */
     395             : 
     396             : /* {{{ zend_implement_arrayaccess */
     397      251123 : static int zend_implement_arrayaccess(zend_class_entry *interface, zend_class_entry *class_type)
     398             : {
     399             : #if 0
     400             :         /* get ht from ce */
     401             :         if (ht->read_dimension != zend_std_read_dimension
     402             :         ||  ht->write_dimension != zend_std_write_dimension
     403             :         ||  ht->has_dimension != zend_std_has_dimension
     404             :         ||  ht->unset_dimension != zend_std_unset_dimension) {
     405             :                 return FAILURE;
     406             :         }
     407             : #endif
     408      251123 :         return SUCCESS;
     409             : }
     410             : /* }}}*/
     411             : 
     412             : /* {{{ zend_user_serialize */
     413          53 : ZEND_API int zend_user_serialize(zval *object, unsigned char **buffer, size_t *buf_len, zend_serialize_data *data)
     414             : {
     415          53 :         zend_class_entry * ce = Z_OBJCE_P(object);
     416             :         zval retval;
     417             :         int result;
     418             : 
     419          53 :         zend_call_method_with_0_params(object, ce, &ce->serialize_func, "serialize", &retval);
     420             : 
     421             : 
     422          54 :         if (Z_TYPE(retval) == IS_UNDEF || EG(exception)) {
     423           1 :                 result = FAILURE;
     424             :         } else {
     425          52 :                 switch(Z_TYPE(retval)) {
     426             :                 case IS_NULL:
     427             :                         /* we could also make this '*buf_len = 0' but this allows to skip variables */
     428           2 :                         zval_ptr_dtor(&retval);
     429           2 :                         return FAILURE;
     430             :                 case IS_STRING:
     431          47 :                         *buffer = (unsigned char*)estrndup(Z_STRVAL(retval), Z_STRLEN(retval));
     432          47 :                         *buf_len = Z_STRLEN(retval);
     433          47 :                         result = SUCCESS;
     434          47 :                         break;
     435             :                 default: /* failure */
     436           3 :                         result = FAILURE;
     437             :                         break;
     438             :                 }
     439          50 :                 zval_ptr_dtor(&retval);
     440             :         }
     441             : 
     442          51 :         if (result == FAILURE && !EG(exception)) {
     443           3 :                 zend_throw_exception_ex(NULL, 0, "%s::serialize() must return a string or NULL", ce->name->val);
     444             :         }
     445          51 :         return result;
     446             : }
     447             : /* }}} */
     448             : 
     449             : /* {{{ zend_user_unserialize */
     450          62 : ZEND_API int zend_user_unserialize(zval *object, zend_class_entry *ce, const unsigned char *buf, size_t buf_len, zend_unserialize_data *data)
     451             : {
     452             :         zval zdata;
     453             : 
     454          62 :         if (UNEXPECTED(object_init_ex(object, ce) != SUCCESS)) {
     455           0 :                 return FAILURE;
     456             :         }
     457             : 
     458         124 :         ZVAL_STRINGL(&zdata, (char*)buf, buf_len);
     459             : 
     460          62 :         zend_call_method_with_1_params(object, ce, &ce->unserialize_func, "unserialize", NULL, &zdata);
     461             : 
     462          62 :         zval_ptr_dtor(&zdata);
     463             : 
     464          62 :         if (EG(exception)) {
     465           0 :                 return FAILURE;
     466             :         } else {
     467          62 :                 return SUCCESS;
     468             :         }
     469             : }
     470             : /* }}} */
     471             : 
     472           1 : ZEND_API int zend_class_serialize_deny(zval *object, unsigned char **buffer, size_t *buf_len, zend_serialize_data *data) /* {{{ */
     473             : {
     474           1 :         zend_class_entry *ce = Z_OBJCE_P(object);
     475           1 :         zend_throw_exception_ex(NULL, 0, "Serialization of '%s' is not allowed", ce->name->val);
     476           1 :         return FAILURE;
     477             : }
     478             : /* }}} */
     479             : 
     480           1 : ZEND_API int zend_class_unserialize_deny(zval *object, zend_class_entry *ce, const unsigned char *buf, size_t buf_len, zend_unserialize_data *data) /* {{{ */
     481             : {
     482           1 :         zend_throw_exception_ex(NULL, 0, "Unserialization of '%s' is not allowed", ce->name->val);
     483           1 :         return FAILURE;
     484             : }
     485             : /* }}} */
     486             : 
     487             : /* {{{ zend_implement_serializable */
     488      146530 : static int zend_implement_serializable(zend_class_entry *interface, zend_class_entry *class_type)
     489             : {
     490      272218 :         if (class_type->parent
     491      209374 :                 && (class_type->parent->serialize || class_type->parent->unserialize)
     492       62844 :                 && !instanceof_function_ex(class_type->parent, zend_ce_serializable, 1)) {
     493           0 :                 return FAILURE;
     494             :         }
     495      146530 :         if (!class_type->serialize) {
     496      146530 :                 class_type->serialize = zend_user_serialize;
     497             :         }
     498      146530 :         if (!class_type->unserialize) {
     499      146530 :                 class_type->unserialize = zend_user_unserialize;
     500             :         }
     501      146530 :         return SUCCESS;
     502             : }
     503             : /* }}}*/
     504             : 
     505             : /* {{{ function tables */
     506             : const zend_function_entry zend_funcs_aggregate[] = {
     507             :         ZEND_ABSTRACT_ME(iterator, getIterator, NULL)
     508             :         ZEND_FE_END
     509             : };
     510             : 
     511             : const zend_function_entry zend_funcs_iterator[] = {
     512             :         ZEND_ABSTRACT_ME(iterator, current,  NULL)
     513             :         ZEND_ABSTRACT_ME(iterator, next,     NULL)
     514             :         ZEND_ABSTRACT_ME(iterator, key,      NULL)
     515             :         ZEND_ABSTRACT_ME(iterator, valid,    NULL)
     516             :         ZEND_ABSTRACT_ME(iterator, rewind,   NULL)
     517             :         ZEND_FE_END
     518             : };
     519             : 
     520             : const zend_function_entry *zend_funcs_traversable    = NULL;
     521             : 
     522             : ZEND_BEGIN_ARG_INFO_EX(arginfo_arrayaccess_offset, 0, 0, 1)
     523             :         ZEND_ARG_INFO(0, offset)
     524             : ZEND_END_ARG_INFO()
     525             : 
     526             : ZEND_BEGIN_ARG_INFO_EX(arginfo_arrayaccess_offset_get, 0, 0, 1) /* actually this should be return by ref but atm cannot be */
     527             :         ZEND_ARG_INFO(0, offset)
     528             : ZEND_END_ARG_INFO()
     529             : 
     530             : ZEND_BEGIN_ARG_INFO_EX(arginfo_arrayaccess_offset_value, 0, 0, 2)
     531             :         ZEND_ARG_INFO(0, offset)
     532             :         ZEND_ARG_INFO(0, value)
     533             : ZEND_END_ARG_INFO()
     534             : 
     535             : const zend_function_entry zend_funcs_arrayaccess[] = {
     536             :         ZEND_ABSTRACT_ME(arrayaccess, offsetExists, arginfo_arrayaccess_offset)
     537             :         ZEND_ABSTRACT_ME(arrayaccess, offsetGet,    arginfo_arrayaccess_offset_get)
     538             :         ZEND_ABSTRACT_ME(arrayaccess, offsetSet,    arginfo_arrayaccess_offset_value)
     539             :         ZEND_ABSTRACT_ME(arrayaccess, offsetUnset,  arginfo_arrayaccess_offset)
     540             :         ZEND_FE_END
     541             : };
     542             : 
     543             : ZEND_BEGIN_ARG_INFO(arginfo_serializable_serialize, 0)
     544             :         ZEND_ARG_INFO(0, serialized)
     545             : ZEND_END_ARG_INFO()
     546             : 
     547             : const zend_function_entry zend_funcs_serializable[] = {
     548             :         ZEND_ABSTRACT_ME(serializable, serialize,   NULL)
     549             :         ZEND_FENTRY(unserialize, NULL, arginfo_serializable_serialize, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT|ZEND_ACC_CTOR)
     550             :         ZEND_FE_END
     551             : };
     552             : /* }}} */
     553             : 
     554             : #define REGISTER_ITERATOR_INTERFACE(class_name, class_name_str) \
     555             :         {\
     556             :                 zend_class_entry ce;\
     557             :                 INIT_CLASS_ENTRY(ce, # class_name_str, zend_funcs_ ## class_name) \
     558             :                 zend_ce_ ## class_name = zend_register_internal_interface(&ce);\
     559             :                 zend_ce_ ## class_name->interface_gets_implemented = zend_implement_ ## class_name;\
     560             :         }
     561             : 
     562             : #define REGISTER_ITERATOR_IMPLEMENT(class_name, interface_name) \
     563             :         zend_class_implements(zend_ce_ ## class_name, 1, zend_ce_ ## interface_name)
     564             : 
     565             : /* {{{ zend_register_interfaces */
     566       20916 : ZEND_API void zend_register_interfaces(void)
     567             : {
     568       20916 :         REGISTER_ITERATOR_INTERFACE(traversable, Traversable);
     569             : 
     570       20916 :         REGISTER_ITERATOR_INTERFACE(aggregate, IteratorAggregate);
     571       20916 :         REGISTER_ITERATOR_IMPLEMENT(aggregate, traversable);
     572             : 
     573       20916 :         REGISTER_ITERATOR_INTERFACE(iterator, Iterator);
     574       20916 :         REGISTER_ITERATOR_IMPLEMENT(iterator, traversable);
     575             : 
     576       20916 :         REGISTER_ITERATOR_INTERFACE(arrayaccess, ArrayAccess);
     577             : 
     578       20916 :         REGISTER_ITERATOR_INTERFACE(serializable, Serializable)
     579       20916 : }
     580             : /* }}} */
     581             : 
     582             : /*
     583             :  * Local variables:
     584             :  * tab-width: 4
     585             :  * c-basic-offset: 4
     586             :  * indent-tabs-mode: t
     587             :  * End:
     588             :  */

Generated by: LCOV version 1.10

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

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