SPL_ADD_CLASS(CachingIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(CachingRecursiveIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(DirectoryIterator, z_list, sub, allow, ce_flags); \
+ SPL_ADD_CLASS(EmptyIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(FilterIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(InfiniteIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(IteratorIterator, z_list, sub, allow, ce_flags); \
zend_class_entry *spl_ce_IteratorIterator;
zend_class_entry *spl_ce_NoRewindIterator;
zend_class_entry *spl_ce_InfiniteIterator;
+zend_class_entry *spl_ce_EmptyIterator;
function_entry spl_funcs_RecursiveIterator[] = {
SPL_ABSTRACT_ME(RecursiveIterator, hasChildren, NULL)
spl_dual_it_fetch(intern, 0 TSRMLS_CC);
}
}
-
} /* }}} */
static zend_function_entry spl_funcs_InfiniteIterator[] = {
SPL_ME(InfiniteIterator, next, NULL, ZEND_ACC_PUBLIC)
};
+/* {{{ proto EmptyIterator::rewind()
+ Does nothing */
+SPL_METHOD(EmptyIterator, rewind)
+{
+} /* }}} */
+
+/* {{{ proto EmptyIterator::valid()
+ Return false */
+SPL_METHOD(EmptyIterator, valid)
+{
+ RETURN_FALSE;
+} /* }}} */
+
+/* {{{ proto EmptyIterator::key()
+ Throws exception */
+SPL_METHOD(EmptyIterator, key)
+{
+ zend_throw_exception(NULL, "Accessing the key of an EmptyIterator", 0 TSRMLS_CC);
+} /* }}} */
+
+/* {{{ proto EmptyIterator::current()
+ Throws exception */
+SPL_METHOD(EmptyIterator, current)
+{
+ zend_throw_exception(NULL, "Accessing the value of an EmptyIterator", 0 TSRMLS_CC);
+} /* }}} */
+
+/* {{{ proto EmptyIterator::next()
+ Does nothing */
+SPL_METHOD(EmptyIterator, next)
+{
+} /* }}} */
+
+static zend_function_entry spl_funcs_EmptyIterator[] = {
+ SPL_ME(EmptyIterator, rewind, NULL, ZEND_ACC_PUBLIC)
+ SPL_ME(EmptyIterator, valid, NULL, ZEND_ACC_PUBLIC)
+ SPL_ME(EmptyIterator, key, NULL, ZEND_ACC_PUBLIC)
+ SPL_ME(EmptyIterator, current, NULL, ZEND_ACC_PUBLIC)
+ SPL_ME(EmptyIterator, next, NULL, ZEND_ACC_PUBLIC)
+};
+
/* {{{ array iterator_to_array(IteratorAggregate it)
Copy the iterator into an array */
PHP_FUNCTION(iterator_to_array)
REGISTER_SPL_IMPLEMENTS(NoRewindIterator, OuterIterator);
REGISTER_SPL_SUB_CLASS_EX(InfiniteIterator, IteratorIterator, spl_dual_it_new, spl_funcs_InfiniteIterator);
+
+ REGISTER_SPL_STD_CLASS_EX(EmptyIterator, NULL, spl_funcs_EmptyIterator);
+ REGISTER_SPL_ITERATOR(EmptyIterator);
return SUCCESS;
}
--- /dev/null
+--TEST--
+SPL: EmptyIterator
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+
+class EmptyIteratorEx extends EmptyIterator
+{
+ function rewind()
+ {
+ echo __METHOD__ . "\n";
+ parent::rewind();
+ }
+ function valid()
+ {
+ echo __METHOD__ . "\n";
+ return parent::valid();
+ }
+ function current()
+ {
+ echo __METHOD__ . "\n";
+ return parent::current();
+ }
+ function key()
+ {
+ echo __METHOD__ . "\n";
+ return parent::key();
+ }
+ function next()
+ {
+ echo __METHOD__ . "\n";
+ parent::next();
+ }
+}
+
+foreach (new EmptyIteratorEx() as $v) {
+ var_dump($v);
+}
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECT--
+EmptyIteratorEx::rewind
+EmptyIteratorEx::valid
+===DONE===