#35267 [Opn->Bgs]: Foreach value overwritten
| From: | tony2001@php.net | Date: | Thu, 17 Nov 2005 17:35:17 +0000 |
| Subject: | #35267 [Opn->Bgs]: Foreach value overwritten | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-88429@lists.php.net to get a copy of this message | ||
ID: 35267
Updated by: tony2001@php.net
Reported By: mdunn at escindex dot com
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: FreeBSD 4.10
PHP Version: 5.0.5
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
$item->product_id = 1 <-
Previous Comments:
------------------------------------------------------------------------
[2005-11-17 18:19:40] mdunn at escindex dot com
Description:
------------
According to the documentation "foreach" operates on a copy of the
specified array and not the array itself. I believe that in PHP5
something has been messed up as it works in PHP4. There was a logic
error in our script (missing double ==), however in PHP4 it had no
effect on the outcome. In PHP5 it actually changed the value.
Screen shots available at http://ww1.escindex.com/phpbug/
Reproduce code:
---------------
$items['product_type'] = 'CPKG';
$items['product_id'] = 2;
foreach($items as $item)
{
if($item->product_type == 'CPKG' && ($item->product_id = 1 ||
$item->product_id == 2))
{
Expected result:
----------------
$items['product_type'] = 'CPKG';
$items['product_id'] = 2;
Actual result:
--------------
$items['product_type'] = 'CPKG';
$items['product_id'] = 1;
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=35267&edit=1