svn: /phpdoc/en/trunk/reference/spl/functions/ iterator-count.xml
| From: | Christoph Michael Becker | Date: | Mon, 24 Aug 2015 18:15:02 +0000 |
| Subject: | svn: /phpdoc/en/trunk/reference/spl/functions/ iterator-count.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-13648@lists.php.net to get a copy of this message | ||
cmb Mon, 24 Aug 2015 18:15:02 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=337605
Log:
iterator_count() may wind iterator beyond its end (fixes #70346)
Bug: https://bugs.php.net/70346 (Open) iterator_count
affets state of iterator
Changed paths:
U phpdoc/en/trunk/reference/spl/functions/iterator-count.xml
Modified: phpdoc/en/trunk/reference/spl/functions/iterator-count.xml
===================================================================
--- phpdoc/en/trunk/reference/spl/functions/iterator-count.xml 2015-08-24 16:15:20 UTC (rev 337604)
+++ phpdoc/en/trunk/reference/spl/functions/iterator-count.xml 2015-08-24 18:15:02 UTC (rev 337605)
@@ -14,6 +14,8 @@
</methodsynopsis>
<para>
Count the elements in an iterator.
+ <function>iterator_count</function> is not guaranteed to retain the current
+ position of the <parameter>iterator</parameter>.
</para>
</refsect1>
@@ -60,6 +62,45 @@
]]>
</screen>
</example>
+ <example>
+ <title><function>iterator_count</function> modifies position</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$iterator = new ArrayIterator(['one', 'two', 'three']);
+var_dump($iterator->current());
+var_dump(iterator_count($iterator));
+var_dump($iterator->current());
+?>
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+string(3) "one"
+int(3)
+NULL
+]]>
+ </screen>
+ </example>
+ <example>
+ <title><function>iterator_count</function> in &foreach;
loops</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$iterator = new ArrayIterator(['one', 'two', 'three']);
+foreach ($iterator as $key => $value) {
+ echo "$key: $value (", iterator_count($iterator), ")\n";
+}?>
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+0: one (3)
+]]>
+ </screen>
+ </example>
</para>
</refsect1>