diff options
author | Marcus Boerger <helly@php.net> | 2004-10-31 20:59:39 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2004-10-31 20:59:39 +0000 |
commit | 9626e9859a045d76f4fdd339c61d9c4345758f68 (patch) | |
tree | 37dbab72e11ffc3c3bf939255177a780dda075a1 | |
parent | b87f16bfbe3b531b87fe4d1a957fa82e91acf9f2 (diff) | |
download | php-git-9626e9859a045d76f4fdd339c61d9c4345758f68.tar.gz |
- Implement EmptyIterator in C
-rwxr-xr-x | ext/spl/internal/emptyiterator.inc (renamed from ext/spl/examples/emptyiterator.inc) | 4 | ||||
-rwxr-xr-x | ext/spl/php_spl.c | 1 | ||||
-rwxr-xr-x | ext/spl/spl_functions.c | 4 | ||||
-rwxr-xr-x | ext/spl/spl_iterators.c | 46 | ||||
-rwxr-xr-x | ext/spl/spl_iterators.h | 1 | ||||
-rwxr-xr-x | ext/spl/tests/iterator_009.phpt | 47 |
6 files changed, 99 insertions, 4 deletions
diff --git a/ext/spl/examples/emptyiterator.inc b/ext/spl/internal/emptyiterator.inc index 2402497b4f..730b45cd7f 100755 --- a/ext/spl/examples/emptyiterator.inc +++ b/ext/spl/internal/emptyiterator.inc @@ -1,7 +1,7 @@ <?php /** @file emptyiterator.inc - * @ingroup Examples + * @ingroup SPL * @brief class EmptyIterator * @author Marcus Boerger * @date 2003 - 2004 @@ -9,7 +9,7 @@ * SPL - Standard PHP Library */ -/** @ingroup Examples +/** @ingroup SPL * @brief An empty Iterator * @author Marcus Boerger * @version 1.0 diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 3fcdd49ef7..f4bfb7d874 100755 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -166,6 +166,7 @@ PHP_FUNCTION(class_implements) 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); \ diff --git a/ext/spl/spl_functions.c b/ext/spl/spl_functions.c index fc9c315ea6..ed7c3da3ea 100755 --- a/ext/spl/spl_functions.c +++ b/ext/spl/spl_functions.c @@ -59,7 +59,9 @@ void spl_register_std_class(zend_class_entry ** ppce, char * class_name, void * *ppce = zend_register_internal_class(&ce TSRMLS_CC); /* entries changed by initialize */ - (*ppce)->create_object = obj_ctor; + if (obj_ctor) { + (*ppce)->create_object = obj_ctor; + } } /* }}} */ diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 410bbb6d8d..ed81cf7af8 100755 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -48,6 +48,7 @@ zend_class_entry *spl_ce_OuterIterator; 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) @@ -1465,7 +1466,6 @@ SPL_METHOD(InfiniteIterator, next) spl_dual_it_fetch(intern, 0 TSRMLS_CC); } } - } /* }}} */ static zend_function_entry spl_funcs_InfiniteIterator[] = { @@ -1473,6 +1473,47 @@ 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) @@ -1607,6 +1648,9 @@ PHP_MINIT_FUNCTION(spl_iterators) 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; } diff --git a/ext/spl/spl_iterators.h b/ext/spl/spl_iterators.h index 5a7391e520..185bf54b59 100755 --- a/ext/spl/spl_iterators.h +++ b/ext/spl/spl_iterators.h @@ -36,6 +36,7 @@ extern zend_class_entry *spl_ce_OuterIterator; extern zend_class_entry *spl_ce_IteratorIterator; extern zend_class_entry *spl_ce_NoRewindIterator; extern zend_class_entry *spl_ce_InfiniteIterator; +extern zend_class_entry *spl_ce_EmptyIterator; PHP_MINIT_FUNCTION(spl_iterators); diff --git a/ext/spl/tests/iterator_009.phpt b/ext/spl/tests/iterator_009.phpt new file mode 100755 index 0000000000..27a3e0655f --- /dev/null +++ b/ext/spl/tests/iterator_009.phpt @@ -0,0 +1,47 @@ +--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=== |