From 964d208b1fce2e332fc0777f8dbe1b026e133179 Mon Sep 17 00:00:00 2001 From: Christoph Michael Becker Date: Mon, 24 Aug 2015 18:15:02 +0000 Subject: [PATCH] iterator_count() may wind iterator beyond its end (fixes #70346) git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@337605 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/spl/functions/iterator-count.xml | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/reference/spl/functions/iterator-count.xml b/reference/spl/functions/iterator-count.xml index d839324d21..d2b117416a 100644 --- a/reference/spl/functions/iterator-count.xml +++ b/reference/spl/functions/iterator-count.xml @@ -14,6 +14,8 @@ Count the elements in an iterator. + iterator_count is not guaranteed to retain the current + position of the iterator. @@ -57,6 +59,45 @@ var_dump(iterator_count($iterator)); + + + + <function>iterator_count</function> modifies position + +current()); +var_dump(iterator_count($iterator)); +var_dump($iterator->current()); +?> +]]> + + &example.outputs; + + + + + + <function>iterator_count</function> in &foreach; loops + + $value) { + echo "$key: $value (", iterator_count($iterator), ")\n"; +}?> +]]> + + &example.outputs; + +