mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
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
This commit is contained in:
parent
9b89b59790
commit
964d208b1f
1 changed files with 41 additions and 0 deletions
|
@ -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>
|
||||
|
||||
|
@ -57,6 +59,45 @@ var_dump(iterator_count($iterator));
|
|||
<screen>
|
||||
<![CDATA[
|
||||
int(4)
|
||||
]]>
|
||||
</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>
|
||||
|
|
Loading…
Reference in a new issue