com php-src: EmptyIterator now implements Countable; fixes bug 60577: ext/spl/internal/emptyiterator.inc ext/spl/spl_iterators.c
ext/spl/tests/bug60577.phpt
| From: | David Soria Parra | Date: | Mon, 16 Sep 2013 02:04:53 +0000 |
| Subject: | com php-src: EmptyIterator now implements Countable; fixes bug 60577: ext/spl/internal/emptyiterator.inc ext/spl/spl_iterators.c ext/spl/tests/bug60577.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-73205@lists.php.net to get a copy of this message | ||
Commit: 8a936e8eb938965b0daaf076c109ec60141e57a7
Author: Levi Morrison <levim@php.net> Thu, 12 Sep 2013 16:03:39 -0600
Committer: David Soria Parra <dsp@php.net> Mon, 16 Sep 2013 04:04:53 +0200
Parents: c0afe829e33c5f5690c6967a102148984836d5aa
Branches: PHP-5.4 PHP-5.5 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=8a936e8eb938965b0daaf076c109ec60141e57a7
Log:
EmptyIterator now implements Countable; fixes bug 60577
(cherry picked from commit 6398844c86bee08abe4ee3f206ecd86ad0a498f9)
Bugs:
https://bugs.php.net/60577
Changed paths:
M ext/spl/internal/emptyiterator.inc
M ext/spl/spl_iterators.c
A ext/spl/tests/bug60577.phpt
Diff:
diff --git a/ext/spl/internal/emptyiterator.inc b/ext/spl/internal/emptyiterator.inc
index ac80e79..d02b15b 100644
--- a/ext/spl/internal/emptyiterator.inc
+++ b/ext/spl/internal/emptyiterator.inc
@@ -15,7 +15,7 @@
* @version 1.0
* @since PHP 5.1
*/
-class EmptyIterator implements Iterator
+class EmptyIterator implements Iterator, Countable
{
/** No operation.
* @return void
@@ -57,6 +57,15 @@ class EmptyIterator implements Iterator
{
// nothing to do
}
+
+ /**
+ * @return int
+ */
+ function count()
+ {
+ return 0;
+ }
+
}
-?>
\ No newline at end of file
+?>
diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c
index eb82476..ad76258 100644
--- a/ext/spl/spl_iterators.c
+++ b/ext/spl/spl_iterators.c
@@ -3279,12 +3279,23 @@ SPL_METHOD(EmptyIterator, next)
}
} /* }}} */
+/* {{{ proto int EmptyIterator::count()
+ Does nothing */
+SPL_METHOD(EmptyIterator, count)
+{
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+ RETURN_LONG(0);
+} /* }}} */
+
static const zend_function_entry spl_funcs_EmptyIterator[] = {
SPL_ME(EmptyIterator, rewind, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
SPL_ME(EmptyIterator, valid, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
SPL_ME(EmptyIterator, key, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
SPL_ME(EmptyIterator, current, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
SPL_ME(EmptyIterator, next, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
+ SPL_ME(EmptyIterator, count, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
PHP_FE_END
};
@@ -3756,6 +3767,7 @@ PHP_MINIT_FUNCTION(spl_iterators)
REGISTER_SPL_STD_CLASS_EX(EmptyIterator, NULL, spl_funcs_EmptyIterator);
REGISTER_SPL_ITERATOR(EmptyIterator);
+ REGISTER_SPL_IMPLEMENTS(EmptyIterator, Countable);
REGISTER_SPL_SUB_CLASS_EX(RecursiveTreeIterator, RecursiveIteratorIterator,
spl_RecursiveTreeIterator_new, spl_funcs_RecursiveTreeIterator);
REGISTER_SPL_CLASS_CONST_LONG(RecursiveTreeIterator, "BYPASS_CURRENT",
RTIT_BYPASS_CURRENT);
diff --git a/ext/spl/tests/bug60577.phpt b/ext/spl/tests/bug60577.phpt
new file mode 100644
index 0000000..33fc133
--- /dev/null
+++ b/ext/spl/tests/bug60577.phpt
@@ -0,0 +1,8 @@
+--TEST--
+count(new EmptyIterator) should return zero
+--FILE--
+<?php
+$it = new EmptyIterator;
+var_dump(count($it));
+--EXPECT--
+int(0)