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: 222 233 95.3 %
Date: 2014-10-22 Functions: 21 21 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Wed, 22 Oct 2014 07:24:42 +0000 (2 days ago)

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