#48897 [Opn->Bgs]: wrong count() behaviour
| From: | colder@php.net | Date: | Sun, 12 Jul 2009 21:57:24 +0000 |
| Subject: | #48897 [Opn->Bgs]: wrong count() behaviour | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-139663@lists.php.net to get a copy of this message | ||
ID: 48897
Updated by: colder@php.net
Reported By: allyouneedis at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: Windows7
PHP Version: 5.3.0
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
That's quite expected, count() returns 6, hence your "for" generates $i
from 0 to 5.
When you delete the key 3, count is 5, hence for generates $i from 0 to
4, which is the reason you don't get the value 5.
Previous Comments:
------------------------------------------------------------------------
[2009-07-12 21:33:29] allyouneedis at gmail dot com
Description:
------------
count counts one element to much on a freshly created array, goes to
normal behaviour after unset()
(apache newest stable, php newest stable, fresh setup just to confirm
the bug, windows 7)
Reproduce code:
---------------
<?php
$sockets = array(0,1,2,3,4,5);
for($i=0,$j=count($sockets);$i<$j;++$i)echo $sockets[$i];
echo '<br>';
for($i=0,$j=count($sockets)+1;$i<$j;++$i)echo $sockets[$i];
echo '<hr>';
unset($sockets[3]);
for($i=0,$j=count($sockets);$i<$j;++$i)echo $sockets[$i];
echo '<br>';
for($i=0,$j=count($sockets)+1;$i<$j;++$i)echo $sockets[$i];
?>
Expected result:
----------------
01234<br>012345<hr>0124<br>01245
Actual result:
--------------
012345<br>012345<hr>0124<br>01245
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48897&edit=1