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:
zval *retval;
return zend_call_method_with_0_params(&object, ce, &ce->iterator_funcs.zf_new_iterator, "getiterator", &retval);
+
}
/* }}} */
{
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 */