1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 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 #include "zend.h"
20 #include "zend_API.h"
21 #include "zend_interfaces.h"
22 #include "zend_exceptions.h"
23
24 ZEND_API zend_class_entry *zend_ce_traversable;
25 ZEND_API zend_class_entry *zend_ce_aggregate;
26 ZEND_API zend_class_entry *zend_ce_iterator;
27 ZEND_API zend_class_entry *zend_ce_arrayaccess;
28 ZEND_API zend_class_entry *zend_ce_serializable;
29 ZEND_API zend_class_entry *zend_ce_countable;
30
31 /* {{{ zend_call_method
32 Only returns the returned zval if retval_ptr != NULL */
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)33 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)
34 {
35 int result;
36 zend_fcall_info fci;
37 zval retval;
38 zval params[2];
39
40 if (param_count > 0) {
41 ZVAL_COPY_VALUE(¶ms[0], arg1);
42 }
43 if (param_count > 1) {
44 ZVAL_COPY_VALUE(¶ms[1], arg2);
45 }
46
47 fci.size = sizeof(fci);
48 fci.object = object ? Z_OBJ_P(object) : NULL;
49 fci.retval = retval_ptr ? retval_ptr : &retval;
50 fci.param_count = param_count;
51 fci.params = params;
52 fci.no_separation = 1;
53
54 if (!fn_proxy && !obj_ce) {
55 /* no interest in caching and no information already present that is
56 * needed later inside zend_call_function. */
57 ZVAL_STRINGL(&fci.function_name, function_name, function_name_len);
58 result = zend_call_function(&fci, NULL);
59 zval_ptr_dtor(&fci.function_name);
60 } else {
61 zend_fcall_info_cache fcic;
62 ZVAL_UNDEF(&fci.function_name); /* Unused */
63
64 if (!obj_ce) {
65 obj_ce = object ? Z_OBJCE_P(object) : NULL;
66 }
67 if (!fn_proxy || !*fn_proxy) {
68 if (EXPECTED(obj_ce)) {
69 fcic.function_handler = zend_hash_str_find_ptr(
70 &obj_ce->function_table, function_name, function_name_len);
71 if (UNEXPECTED(fcic.function_handler == NULL)) {
72 /* error at c-level */
73 zend_error_noreturn(E_CORE_ERROR, "Couldn't find implementation for method %s::%s", ZSTR_VAL(obj_ce->name), function_name);
74 }
75 } else {
76 fcic.function_handler = zend_fetch_function_str(function_name, function_name_len);
77 if (UNEXPECTED(fcic.function_handler == NULL)) {
78 /* error at c-level */
79 zend_error_noreturn(E_CORE_ERROR, "Couldn't find implementation for function %s", function_name);
80 }
81 }
82 if (fn_proxy) {
83 *fn_proxy = fcic.function_handler;
84 }
85 } else {
86 fcic.function_handler = *fn_proxy;
87 }
88
89 if (object) {
90 fcic.called_scope = Z_OBJCE_P(object);
91 } else {
92 zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data));
93
94 if (obj_ce &&
95 (!called_scope ||
96 !instanceof_function(called_scope, obj_ce))) {
97 fcic.called_scope = obj_ce;
98 } else {
99 fcic.called_scope = called_scope;
100 }
101 }
102 fcic.object = object ? Z_OBJ_P(object) : NULL;
103 result = zend_call_function(&fci, &fcic);
104 }
105 if (result == FAILURE) {
106 /* error at c-level */
107 if (!obj_ce) {
108 obj_ce = object ? Z_OBJCE_P(object) : NULL;
109 }
110 if (!EG(exception)) {
111 zend_error_noreturn(E_CORE_ERROR, "Couldn't execute method %s%s%s", obj_ce ? ZSTR_VAL(obj_ce->name) : "", obj_ce ? "::" : "", function_name);
112 }
113 }
114 if (!retval_ptr) {
115 zval_ptr_dtor(&retval);
116 return NULL;
117 }
118 return retval_ptr;
119 }
120 /* }}} */
121
122 /* iterator interface, c-level functions used by engine */
123
124 /* {{{ zend_user_it_new_iterator */
zend_user_it_new_iterator(zend_class_entry * ce,zval * object,zval * retval)125 ZEND_API void zend_user_it_new_iterator(zend_class_entry *ce, zval *object, zval *retval)
126 {
127 zend_call_method_with_0_params(object, ce, &ce->iterator_funcs_ptr->zf_new_iterator, "getiterator", retval);
128 }
129 /* }}} */
130
131 /* {{{ zend_user_it_invalidate_current */
zend_user_it_invalidate_current(zend_object_iterator * _iter)132 ZEND_API void zend_user_it_invalidate_current(zend_object_iterator *_iter)
133 {
134 zend_user_iterator *iter = (zend_user_iterator*)_iter;
135
136 if (!Z_ISUNDEF(iter->value)) {
137 zval_ptr_dtor(&iter->value);
138 ZVAL_UNDEF(&iter->value);
139 }
140 }
141 /* }}} */
142
143 /* {{{ zend_user_it_dtor */
zend_user_it_dtor(zend_object_iterator * _iter)144 static void zend_user_it_dtor(zend_object_iterator *_iter)
145 {
146 zend_user_iterator *iter = (zend_user_iterator*)_iter;
147 zval *object = &iter->it.data;
148
149 zend_user_it_invalidate_current(_iter);
150 zval_ptr_dtor(object);
151 }
152 /* }}} */
153
154 /* {{{ zend_user_it_valid */
zend_user_it_valid(zend_object_iterator * _iter)155 ZEND_API int zend_user_it_valid(zend_object_iterator *_iter)
156 {
157 if (_iter) {
158 zend_user_iterator *iter = (zend_user_iterator*)_iter;
159 zval *object = &iter->it.data;
160 zval more;
161 int result;
162
163 zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs_ptr->zf_valid, "valid", &more);
164 result = i_zend_is_true(&more);
165 zval_ptr_dtor(&more);
166 return result ? SUCCESS : FAILURE;
167 }
168 return FAILURE;
169 }
170 /* }}} */
171
172 /* {{{ zend_user_it_get_current_data */
zend_user_it_get_current_data(zend_object_iterator * _iter)173 ZEND_API zval *zend_user_it_get_current_data(zend_object_iterator *_iter)
174 {
175 zend_user_iterator *iter = (zend_user_iterator*)_iter;
176 zval *object = &iter->it.data;
177
178 if (Z_ISUNDEF(iter->value)) {
179 zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs_ptr->zf_current, "current", &iter->value);
180 }
181 return &iter->value;
182 }
183 /* }}} */
184
185 /* {{{ zend_user_it_get_current_key */
zend_user_it_get_current_key(zend_object_iterator * _iter,zval * key)186 ZEND_API void zend_user_it_get_current_key(zend_object_iterator *_iter, zval *key)
187 {
188 zend_user_iterator *iter = (zend_user_iterator*)_iter;
189 zval *object = &iter->it.data;
190 zval retval;
191
192 zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs_ptr->zf_key, "key", &retval);
193
194 if (Z_TYPE(retval) != IS_UNDEF) {
195 ZVAL_ZVAL(key, &retval, 1, 1);
196 } else {
197 if (!EG(exception)) {
198 zend_error(E_WARNING, "Nothing returned from %s::key()", ZSTR_VAL(iter->ce->name));
199 }
200
201 ZVAL_LONG(key, 0);
202 }
203 }
204 /* }}} */
205
206 /* {{{ zend_user_it_move_forward */
zend_user_it_move_forward(zend_object_iterator * _iter)207 ZEND_API void zend_user_it_move_forward(zend_object_iterator *_iter)
208 {
209 zend_user_iterator *iter = (zend_user_iterator*)_iter;
210 zval *object = &iter->it.data;
211
212 zend_user_it_invalidate_current(_iter);
213 zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs_ptr->zf_next, "next", NULL);
214 }
215 /* }}} */
216
217 /* {{{ zend_user_it_rewind */
zend_user_it_rewind(zend_object_iterator * _iter)218 ZEND_API void zend_user_it_rewind(zend_object_iterator *_iter)
219 {
220 zend_user_iterator *iter = (zend_user_iterator*)_iter;
221 zval *object = &iter->it.data;
222
223 zend_user_it_invalidate_current(_iter);
224 zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs_ptr->zf_rewind, "rewind", NULL);
225 }
226 /* }}} */
227
228 static const zend_object_iterator_funcs zend_interface_iterator_funcs_iterator = {
229 zend_user_it_dtor,
230 zend_user_it_valid,
231 zend_user_it_get_current_data,
232 zend_user_it_get_current_key,
233 zend_user_it_move_forward,
234 zend_user_it_rewind,
235 zend_user_it_invalidate_current
236 };
237
238 /* {{{ zend_user_it_get_iterator */
zend_user_it_get_iterator(zend_class_entry * ce,zval * object,int by_ref)239 static zend_object_iterator *zend_user_it_get_iterator(zend_class_entry *ce, zval *object, int by_ref)
240 {
241 zend_user_iterator *iterator;
242
243 if (by_ref) {
244 zend_throw_error(NULL, "An iterator cannot be used with foreach by reference");
245 return NULL;
246 }
247
248 iterator = emalloc(sizeof(zend_user_iterator));
249
250 zend_iterator_init((zend_object_iterator*)iterator);
251
252 Z_ADDREF_P(object);
253 ZVAL_OBJ(&iterator->it.data, Z_OBJ_P(object));
254 iterator->it.funcs = &zend_interface_iterator_funcs_iterator;
255 iterator->ce = Z_OBJCE_P(object);
256 ZVAL_UNDEF(&iterator->value);
257 return (zend_object_iterator*)iterator;
258 }
259 /* }}} */
260
261 /* {{{ zend_user_it_get_new_iterator */
zend_user_it_get_new_iterator(zend_class_entry * ce,zval * object,int by_ref)262 ZEND_API zend_object_iterator *zend_user_it_get_new_iterator(zend_class_entry *ce, zval *object, int by_ref)
263 {
264 zval iterator;
265 zend_object_iterator *new_iterator;
266 zend_class_entry *ce_it;
267
268 zend_user_it_new_iterator(ce, object, &iterator);
269 ce_it = (Z_TYPE(iterator) == IS_OBJECT) ? Z_OBJCE(iterator) : NULL;
270
271 if (!ce_it || !ce_it->get_iterator || (ce_it->get_iterator == zend_user_it_get_new_iterator && Z_OBJ(iterator) == Z_OBJ_P(object))) {
272 if (!EG(exception)) {
273 zend_throw_exception_ex(NULL, 0, "Objects returned by %s::getIterator() must be traversable or implement interface Iterator", ce ? ZSTR_VAL(ce->name) : ZSTR_VAL(Z_OBJCE_P(object)->name));
274 }
275 zval_ptr_dtor(&iterator);
276 return NULL;
277 }
278
279 new_iterator = ce_it->get_iterator(ce_it, &iterator, by_ref);
280 zval_ptr_dtor(&iterator);
281 return new_iterator;
282 }
283 /* }}} */
284
285 /* {{{ zend_implement_traversable */
zend_implement_traversable(zend_class_entry * interface,zend_class_entry * class_type)286 static int zend_implement_traversable(zend_class_entry *interface, zend_class_entry *class_type)
287 {
288 /* check that class_type is traversable at c-level or implements at least one of 'aggregate' and 'Iterator' */
289 uint32_t i;
290
291 if (class_type->get_iterator || (class_type->parent && class_type->parent->get_iterator)) {
292 return SUCCESS;
293 }
294 if (class_type->num_interfaces) {
295 ZEND_ASSERT(class_type->ce_flags & ZEND_ACC_RESOLVED_INTERFACES);
296 for (i = 0; i < class_type->num_interfaces; i++) {
297 if (class_type->interfaces[i] == zend_ce_aggregate || class_type->interfaces[i] == zend_ce_iterator) {
298 return SUCCESS;
299 }
300 }
301 }
302 zend_error_noreturn(E_CORE_ERROR, "Class %s must implement interface %s as part of either %s or %s",
303 ZSTR_VAL(class_type->name),
304 ZSTR_VAL(zend_ce_traversable->name),
305 ZSTR_VAL(zend_ce_iterator->name),
306 ZSTR_VAL(zend_ce_aggregate->name));
307 return FAILURE;
308 }
309 /* }}} */
310
311 /* {{{ zend_implement_aggregate */
zend_implement_aggregate(zend_class_entry * interface,zend_class_entry * class_type)312 static int zend_implement_aggregate(zend_class_entry *interface, zend_class_entry *class_type)
313 {
314 uint32_t i;
315 int t = -1;
316 zend_class_iterator_funcs *funcs_ptr;
317
318 if (class_type->get_iterator) {
319 if (class_type->type == ZEND_INTERNAL_CLASS) {
320 /* inheritance ensures the class has necessary userland methods */
321 return SUCCESS;
322 } else if (class_type->get_iterator != zend_user_it_get_new_iterator) {
323 /* c-level get_iterator cannot be changed (exception being only Traversable is implemented) */
324 if (class_type->num_interfaces) {
325 ZEND_ASSERT(class_type->ce_flags & ZEND_ACC_RESOLVED_INTERFACES);
326 for (i = 0; i < class_type->num_interfaces; i++) {
327 if (class_type->interfaces[i] == zend_ce_iterator) {
328 zend_error_noreturn(E_ERROR, "Class %s cannot implement both %s and %s at the same time",
329 ZSTR_VAL(class_type->name),
330 ZSTR_VAL(interface->name),
331 ZSTR_VAL(zend_ce_iterator->name));
332 return FAILURE;
333 }
334 if (class_type->interfaces[i] == zend_ce_traversable) {
335 t = i;
336 }
337 }
338 }
339 if (t == -1) {
340 return FAILURE;
341 }
342 }
343 }
344 if (class_type->parent
345 && (class_type->parent->ce_flags & ZEND_ACC_REUSE_GET_ITERATOR)) {
346 class_type->get_iterator = class_type->parent->get_iterator;
347 class_type->ce_flags |= ZEND_ACC_REUSE_GET_ITERATOR;
348 } else {
349 class_type->get_iterator = zend_user_it_get_new_iterator;
350 }
351 funcs_ptr = class_type->iterator_funcs_ptr;
352 if (class_type->type == ZEND_INTERNAL_CLASS) {
353 if (!funcs_ptr) {
354 funcs_ptr = calloc(1, sizeof(zend_class_iterator_funcs));
355 class_type->iterator_funcs_ptr = funcs_ptr;
356 }
357 funcs_ptr->zf_new_iterator = zend_hash_str_find_ptr(&class_type->function_table, "getiterator", sizeof("getiterator") - 1);
358 } else {
359 if (!funcs_ptr) {
360 funcs_ptr = zend_arena_alloc(&CG(arena), sizeof(zend_class_iterator_funcs));
361 class_type->iterator_funcs_ptr = funcs_ptr;
362 memset(funcs_ptr, 0, sizeof(zend_class_iterator_funcs));
363 } else {
364 funcs_ptr->zf_new_iterator = NULL;
365 }
366 }
367 return SUCCESS;
368 }
369 /* }}} */
370
371 /* {{{ zend_implement_iterator */
zend_implement_iterator(zend_class_entry * interface,zend_class_entry * class_type)372 static int zend_implement_iterator(zend_class_entry *interface, zend_class_entry *class_type)
373 {
374 zend_class_iterator_funcs *funcs_ptr;
375
376 if (class_type->get_iterator && class_type->get_iterator != zend_user_it_get_iterator) {
377 if (class_type->type == ZEND_INTERNAL_CLASS) {
378 /* inheritance ensures the class has the necessary userland methods */
379 return SUCCESS;
380 } else {
381 /* c-level get_iterator cannot be changed */
382 if (class_type->get_iterator == zend_user_it_get_new_iterator) {
383 zend_error_noreturn(E_ERROR, "Class %s cannot implement both %s and %s at the same time",
384 ZSTR_VAL(class_type->name),
385 ZSTR_VAL(interface->name),
386 ZSTR_VAL(zend_ce_aggregate->name));
387 }
388 return FAILURE;
389 }
390 }
391 if (class_type->parent
392 && (class_type->parent->ce_flags & ZEND_ACC_REUSE_GET_ITERATOR)) {
393 class_type->get_iterator = class_type->parent->get_iterator;
394 class_type->ce_flags |= ZEND_ACC_REUSE_GET_ITERATOR;
395 } else {
396 class_type->get_iterator = zend_user_it_get_iterator;
397 }
398 funcs_ptr = class_type->iterator_funcs_ptr;
399 if (class_type->type == ZEND_INTERNAL_CLASS) {
400 if (!funcs_ptr) {
401 funcs_ptr = calloc(1, sizeof(zend_class_iterator_funcs));
402 class_type->iterator_funcs_ptr = funcs_ptr;
403 } else {
404 funcs_ptr->zf_rewind = zend_hash_str_find_ptr(&class_type->function_table, "rewind", sizeof("rewind") - 1);
405 funcs_ptr->zf_valid = zend_hash_str_find_ptr(&class_type->function_table, "valid", sizeof("valid") - 1);
406 funcs_ptr->zf_key = zend_hash_str_find_ptr(&class_type->function_table, "key", sizeof("key") - 1);
407 funcs_ptr->zf_current = zend_hash_str_find_ptr(&class_type->function_table, "current", sizeof("current") - 1);
408 funcs_ptr->zf_next = zend_hash_str_find_ptr(&class_type->function_table, "next", sizeof("next") - 1);
409 }
410 } else {
411 if (!funcs_ptr) {
412 funcs_ptr = zend_arena_alloc(&CG(arena), sizeof(zend_class_iterator_funcs));
413 class_type->iterator_funcs_ptr = funcs_ptr;
414 memset(funcs_ptr, 0, sizeof(zend_class_iterator_funcs));
415 } else {
416 funcs_ptr->zf_valid = NULL;
417 funcs_ptr->zf_current = NULL;
418 funcs_ptr->zf_key = NULL;
419 funcs_ptr->zf_next = NULL;
420 funcs_ptr->zf_rewind = NULL;
421 }
422 }
423 return SUCCESS;
424 }
425 /* }}} */
426
427 /* {{{ zend_implement_arrayaccess */
zend_implement_arrayaccess(zend_class_entry * interface,zend_class_entry * class_type)428 static int zend_implement_arrayaccess(zend_class_entry *interface, zend_class_entry *class_type)
429 {
430 return SUCCESS;
431 }
432 /* }}}*/
433
434 /* {{{ zend_user_serialize */
zend_user_serialize(zval * object,unsigned char ** buffer,size_t * buf_len,zend_serialize_data * data)435 ZEND_API int zend_user_serialize(zval *object, unsigned char **buffer, size_t *buf_len, zend_serialize_data *data)
436 {
437 zend_class_entry * ce = Z_OBJCE_P(object);
438 zval retval;
439 int result;
440
441 zend_call_method_with_0_params(object, ce, &ce->serialize_func, "serialize", &retval);
442
443
444 if (Z_TYPE(retval) == IS_UNDEF || EG(exception)) {
445 result = FAILURE;
446 } else {
447 switch(Z_TYPE(retval)) {
448 case IS_NULL:
449 /* we could also make this '*buf_len = 0' but this allows to skip variables */
450 zval_ptr_dtor(&retval);
451 return FAILURE;
452 case IS_STRING:
453 *buffer = (unsigned char*)estrndup(Z_STRVAL(retval), Z_STRLEN(retval));
454 *buf_len = Z_STRLEN(retval);
455 result = SUCCESS;
456 break;
457 default: /* failure */
458 result = FAILURE;
459 break;
460 }
461 zval_ptr_dtor(&retval);
462 }
463
464 if (result == FAILURE && !EG(exception)) {
465 zend_throw_exception_ex(NULL, 0, "%s::serialize() must return a string or NULL", ZSTR_VAL(ce->name));
466 }
467 return result;
468 }
469 /* }}} */
470
471 /* {{{ zend_user_unserialize */
zend_user_unserialize(zval * object,zend_class_entry * ce,const unsigned char * buf,size_t buf_len,zend_unserialize_data * data)472 ZEND_API int zend_user_unserialize(zval *object, zend_class_entry *ce, const unsigned char *buf, size_t buf_len, zend_unserialize_data *data)
473 {
474 zval zdata;
475
476 if (UNEXPECTED(object_init_ex(object, ce) != SUCCESS)) {
477 return FAILURE;
478 }
479
480 ZVAL_STRINGL(&zdata, (char*)buf, buf_len);
481
482 zend_call_method_with_1_params(object, ce, &ce->unserialize_func, "unserialize", NULL, &zdata);
483
484 zval_ptr_dtor(&zdata);
485
486 if (EG(exception)) {
487 return FAILURE;
488 } else {
489 return SUCCESS;
490 }
491 }
492 /* }}} */
493
zend_class_serialize_deny(zval * object,unsigned char ** buffer,size_t * buf_len,zend_serialize_data * data)494 ZEND_API int zend_class_serialize_deny(zval *object, unsigned char **buffer, size_t *buf_len, zend_serialize_data *data) /* {{{ */
495 {
496 zend_class_entry *ce = Z_OBJCE_P(object);
497 zend_throw_exception_ex(NULL, 0, "Serialization of '%s' is not allowed", ZSTR_VAL(ce->name));
498 return FAILURE;
499 }
500 /* }}} */
501
zend_class_unserialize_deny(zval * object,zend_class_entry * ce,const unsigned char * buf,size_t buf_len,zend_unserialize_data * data)502 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) /* {{{ */
503 {
504 zend_throw_exception_ex(NULL, 0, "Unserialization of '%s' is not allowed", ZSTR_VAL(ce->name));
505 return FAILURE;
506 }
507 /* }}} */
508
509 /* {{{ zend_implement_serializable */
zend_implement_serializable(zend_class_entry * interface,zend_class_entry * class_type)510 static int zend_implement_serializable(zend_class_entry *interface, zend_class_entry *class_type)
511 {
512 if (class_type->parent
513 && (class_type->parent->serialize || class_type->parent->unserialize)
514 && !instanceof_function_ex(class_type->parent, zend_ce_serializable, 1)) {
515 return FAILURE;
516 }
517 if (!class_type->serialize) {
518 class_type->serialize = zend_user_serialize;
519 }
520 if (!class_type->unserialize) {
521 class_type->unserialize = zend_user_unserialize;
522 }
523 return SUCCESS;
524 }
525 /* }}}*/
526
527 /* {{{ zend_implement_countable */
zend_implement_countable(zend_class_entry * interface,zend_class_entry * class_type)528 static int zend_implement_countable(zend_class_entry *interface, zend_class_entry *class_type)
529 {
530 return SUCCESS;
531 }
532 /* }}}*/
533
534 /* {{{ function tables */
535 static const zend_function_entry zend_funcs_aggregate[] = {
536 ZEND_ABSTRACT_ME(iterator, getIterator, NULL)
537 ZEND_FE_END
538 };
539
540 static const zend_function_entry zend_funcs_iterator[] = {
541 ZEND_ABSTRACT_ME(iterator, current, NULL)
542 ZEND_ABSTRACT_ME(iterator, next, NULL)
543 ZEND_ABSTRACT_ME(iterator, key, NULL)
544 ZEND_ABSTRACT_ME(iterator, valid, NULL)
545 ZEND_ABSTRACT_ME(iterator, rewind, NULL)
546 ZEND_FE_END
547 };
548
549 static const zend_function_entry *zend_funcs_traversable = NULL;
550
551 ZEND_BEGIN_ARG_INFO_EX(arginfo_arrayaccess_offset, 0, 0, 1)
552 ZEND_ARG_INFO(0, offset)
553 ZEND_END_ARG_INFO()
554
555 ZEND_BEGIN_ARG_INFO_EX(arginfo_arrayaccess_offset_get, 0, 0, 1) /* actually this should be return by ref but atm cannot be */
556 ZEND_ARG_INFO(0, offset)
557 ZEND_END_ARG_INFO()
558
559 ZEND_BEGIN_ARG_INFO_EX(arginfo_arrayaccess_offset_value, 0, 0, 2)
560 ZEND_ARG_INFO(0, offset)
561 ZEND_ARG_INFO(0, value)
562 ZEND_END_ARG_INFO()
563
564 static const zend_function_entry zend_funcs_arrayaccess[] = {
565 ZEND_ABSTRACT_ME(arrayaccess, offsetExists, arginfo_arrayaccess_offset)
566 ZEND_ABSTRACT_ME(arrayaccess, offsetGet, arginfo_arrayaccess_offset_get)
567 ZEND_ABSTRACT_ME(arrayaccess, offsetSet, arginfo_arrayaccess_offset_value)
568 ZEND_ABSTRACT_ME(arrayaccess, offsetUnset, arginfo_arrayaccess_offset)
569 ZEND_FE_END
570 };
571
572 ZEND_BEGIN_ARG_INFO(arginfo_serializable_serialize, 0)
573 ZEND_ARG_INFO(0, serialized)
574 ZEND_END_ARG_INFO()
575
576 static const zend_function_entry zend_funcs_serializable[] = {
577 ZEND_ABSTRACT_ME(serializable, serialize, NULL)
578 ZEND_FENTRY(unserialize, NULL, arginfo_serializable_serialize, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
579 ZEND_FE_END
580 };
581
582 ZEND_BEGIN_ARG_INFO(arginfo_countable_count, 0)
583 ZEND_END_ARG_INFO()
584
585 static const zend_function_entry zend_funcs_countable[] = {
586 ZEND_ABSTRACT_ME(Countable, count, arginfo_countable_count)
587 ZEND_FE_END
588 };
589 /* }}} */
590
591 /* {{{ zend_register_interfaces */
zend_register_interfaces(void)592 ZEND_API void zend_register_interfaces(void)
593 {
594 REGISTER_MAGIC_INTERFACE(traversable, Traversable);
595
596 REGISTER_MAGIC_INTERFACE(aggregate, IteratorAggregate);
597 REGISTER_MAGIC_IMPLEMENT(aggregate, traversable);
598
599 REGISTER_MAGIC_INTERFACE(iterator, Iterator);
600 REGISTER_MAGIC_IMPLEMENT(iterator, traversable);
601
602 REGISTER_MAGIC_INTERFACE(arrayaccess, ArrayAccess);
603
604 REGISTER_MAGIC_INTERFACE(serializable, Serializable);
605
606 REGISTER_MAGIC_INTERFACE(countable, Countable);
607 }
608 /* }}} */
609