Bug #51829 [Opn->Bgs]: Array output unexpected result
| From: | dtajchreber@php.net | Date: | Fri, 14 May 2010 19:44:20 +0000 |
| Subject: | Bug #51829 [Opn->Bgs]: Array output unexpected result | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-150481@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=51829&edit=1
ID: 51829
Updated by: dtajchreber@php.net
Reported by: josefrancklin at yahoo dot com dot br
Summary: Array output unexpected result
-Status: Open
+Status: Bogus
Type: Bug
Package: Arrays related
Operating System: Windows XP
PHP Version: 5.3.2
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
You have discovered type juggling. See:
http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion
'x' turns into 0. 0 == 0. Your if statement is never executed.
Previous Comments:
------------------------------------------------------------------------
[2010-05-14 20:09:16] josefrancklin at yahoo dot com dot br
Description:
------------
Code typed below generates unexpected result in the [0] term from an
array.
Test script:
---------------
for ($i=0;$i<3;$i++)
{
$array_id=array( 0 => 0 , 1 => 1 , 2 => 2 );
$array_id[$i]="x";
for ($j=0;$j<3;$j++)
{
print "term [$j] is $array_id[$j]";
if ($array_id[$j]!=$j)
print ", not $j";
print "<BR>\n";
}
print "<BR>\n";
}
Expected result:
----------------
term [0] is x, not 0
term [1] is 1
term [2] is 2
term [0] is 0
term [1] is x, not 1
term [2] is 2
term [0] is 0
term [1] is 1
term [2] is x, not 2
Actual result:
--------------
array[0] is x
array[1] is 1
array[2] is 2
array[0] is 0
array[1] is x, not 1
array[2] is 2
array[0] is 0
array[1] is 1
array[2] is x, not 2
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51829&edit=1