]> granicus.if.org Git - php/commitdiff
IteratorAggregate::getIterator() cannot return anythingy else than objects
authorMarcus Boerger <helly@php.net>
Thu, 13 Nov 2003 08:23:49 +0000 (08:23 +0000)
committerMarcus Boerger <helly@php.net>
Thu, 13 Nov 2003 08:23:49 +0000 (08:23 +0000)
Zend/ZEND_CHANGES
Zend/zend_interfaces.c

index 3d3d015820f6f1eefbfba4ac59ac3c6e952eb732..302b80f606fbe48809e0e37f2cae196ec5da27e6 100644 (file)
@@ -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:
 
index b1cb5e4e5fa58fcb2d867aaa1e93900253c7d51f..aa857af396c37f00712d6d39d710795e4b48ab07 100755 (executable)
@@ -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 */