Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > #41364 : Auto increment problem
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 21st July 22:02
php-bugs
External User
 
Posts: 1
Default #41364 : Auto increment problem



From: wimroffel at planet dot nl
Operating system: Windows XP
PHP version: 5.2.2
PHP Bug Type: Unknown/Other Function
Bug description: Auto increment problem

Description:
------------
When I have a loop

for($i=0; $i<$size
{ $myarr[$i][3] = $i++;
}

PHP will first take the assigned value, then increase $i and that use the
new $i to set the array. So the first loop will do:
$myarr[1][3]=0;

I come from PHP4 and there this worked correctly (first line
$myarr[0][3]=0.

I am using XAMPP and as a consequence PHP 5.2.1. But I couldn't find this
in the bug database so I suppose it has not been solved.

Reproduce code:
---------------
$myarr = array();
$myarr[0] = array("A","B","C");
$myarr[1] = array("D","E","F");
$myarr[2] = array("G","H","I");
$size = sizeof($myarr);
echo "The size of myarr is ".$size."<br>";
for($i=0; $i<$size
{ $myarr[$i][3] = $i++;
}

for($i=0; $i<$size; $i++)
{ echo "Record ".$i." = ".$myarr[$i][3]."<br>";
}
echo "The size of the array is now ".sizeof($myarr);

Expected result:
----------------
The size of myarr is 3
Record 0 = 0
Record 1 = 1
Record 2 = 2
The size of the array is now 3

Actual result:
--------------
The size of myarr is 3
Record 0 =
Record 1 = 0
Record 2 = 1
The size of the array is now 4

--
Edit bug report at http://bugs.php.net/?id=41364&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41364&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41364&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41364&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=41364&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=41364&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=41364&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=41364&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=41364&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=41364&r=support
Expected behavior: http://bugs.php.net/fix.php?id=41364&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=41364&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=41364&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=41364&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41364&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=41364&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=41364&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=41364&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=41364&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=41364&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=41364&r=mysqlcfg
  Reply With Quote


  sponsored links


2 21st July 22:02
External User
 
Posts: 1
Default #41364 : Auto increment problem



ID: 41364
Updated by: tony2001@php.net
Reported By: wimroffel at planet dot nl
-Status: Open
+Status: Bogus
Bug Type: Unknown/Other Function
Operating System: Windows XP
PHP Version: 5.2.2
New Comment:

This behaviour is undefined in all languages including PHP.


Previous Comments:
------------------------------------------------------------------------

[2007-05-11 13:11:44] wimroffel at planet dot nl

Description:
------------
When I have a loop

for($i=0; $i<$size
{ $myarr[$i][3] = $i++;
}

PHP will first take the assigned value, then increase $i and that use
the new $i to set the array. So the first loop will do:
$myarr[1][3]=0;

I come from PHP4 and there this worked correctly (first line
$myarr[0][3]=0.

I am using XAMPP and as a consequence PHP 5.2.1. But I couldn't find
this in the bug database so I suppose it has not been solved.

Reproduce code:
---------------
$myarr = array();
$myarr[0] = array("A","B","C");
$myarr[1] = array("D","E","F");
$myarr[2] = array("G","H","I");
$size = sizeof($myarr);
echo "The size of myarr is ".$size."<br>";
for($i=0; $i<$size
{ $myarr[$i][3] = $i++;
}

for($i=0; $i<$size; $i++)
{ echo "Record ".$i." = ".$myarr[$i][3]."<br>";
}
echo "The size of the array is now ".sizeof($myarr);

Expected result:
----------------
The size of myarr is 3
Record 0 = 0
Record 1 = 1
Record 2 = 2
The size of the array is now 3

Actual result:
--------------
The size of myarr is 3
Record 0 =
Record 1 = 0
Record 2 = 1
The size of the array is now 4


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=41364&edit=1
  Reply With Quote
3 22nd July 01:04
php-bugs
External User
 
Posts: 1
Default #41364 : Auto increment problem


ID: 41364
User updated by: wimroffel at planet dot nl
Reported By: wimroffel at planet dot nl
Status: Bogus
Bug Type: Unknown/Other Function
Operating System: Windows XP
PHP Version: 5.2.2
New Comment:

That sounds like a very weak excuse to change the working of the
language and causing me and probably many others many hours of
debugging.


Previous Comments:
------------------------------------------------------------------------

[2007-05-11 13:14:01] tony2001@php.net

This behaviour is undefined in all languages including PHP.

------------------------------------------------------------------------

[2007-05-11 13:11:44] wimroffel at planet dot nl

Description:
------------
When I have a loop

for($i=0; $i<$size
{ $myarr[$i][3] = $i++;
}

PHP will first take the assigned value, then increase $i and that use
the new $i to set the array. So the first loop will do:
$myarr[1][3]=0;

I come from PHP4 and there this worked correctly (first line
$myarr[0][3]=0.

I am using XAMPP and as a consequence PHP 5.2.1. But I couldn't find
this in the bug database so I suppose it has not been solved.

Reproduce code:
---------------
$myarr = array();
$myarr[0] = array("A","B","C");
$myarr[1] = array("D","E","F");
$myarr[2] = array("G","H","I");
$size = sizeof($myarr);
echo "The size of myarr is ".$size."<br>";
for($i=0; $i<$size
{ $myarr[$i][3] = $i++;
}

for($i=0; $i<$size; $i++)
{ echo "Record ".$i." = ".$myarr[$i][3]."<br>";
}
echo "The size of the array is now ".sizeof($myarr);

Expected result:
----------------
The size of myarr is 3
Record 0 = 0
Record 1 = 1
Record 2 = 2
The size of the array is now 3

Actual result:
--------------
The size of myarr is 3
Record 0 =
Record 1 = 0
Record 2 = 1
The size of the array is now 4


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=41364&edit=1
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666