Permalink
Browse files

IteratorAggregate::getIterator() cannot return anythingy else than ob…

…jects
  • Loading branch information...
1 parent 4d752bd commit 58246412a7b653ce33c5026df3215878f96b82d4 Marcus Boerger committed Nov 13, 2003
Showing with 8 additions and 5 deletions.
  1. +3 −3 Zend/ZEND_CHANGES
  2. +5 −2 Zend/zend_interfaces.c
View
6 Zend/ZEND_CHANGES
@@ -743,9 +743,9 @@ Changes in the Zend Engine 2.0
The interfaces 'IteratorAggregate' and 'Iterator' allow to specify
how class objects are iterated in PHP code. The first of them simply
- has a method 'getIterator' which must return an array or an object
- that either implements the interface 'Iterator' or is instantiated
- from an internal class that can be iterated.
+ has a method 'getIterator' which must return an object that either
+ implements the interface 'Iterator' or is instantiated from an
+ internal class that can be iterated.
Example:
View
7 Zend/zend_interfaces.c
@@ -109,6 +109,7 @@ static zval *zend_user_new_iterator(zend_class_entry *ce, zval *object TSRMLS_DC
zval *retval;
return zend_call_method_with_0_params(&object, ce, &ce->iterator_funcs.zf_new_iterator, "getiterator", &retval);
+
}
/* }}} */
@@ -265,9 +266,11 @@ static zend_object_iterator *zend_user_get_new_iterator(zend_class_entry *ce, zv
{
zval *iterator = zend_user_new_iterator(ce, object TSRMLS_CC);
- zend_class_entry *ce_it = Z_OBJCE_P(iterator);
- if (!ce || !ce_it->get_iterator) {
+ zend_class_entry *ce_it = Z_TYPE_P(iterator) == IS_OBJECT ? Z_OBJCE_P(iterator) : NULL;
+
+ if (!ce || !ce_it || !ce_it->get_iterator) {
zend_error(E_WARNING, "Objects returned by %s::getIterator() must be traversable or implement interface Iterator", ce->name);
+ zval_ptr_dtor(&iterator);
return NULL;
}
iterator->refcount--; /* from return */

0 comments on commit 5824641

Please sign in to comment.