Bug #1528: Sometimes array element is converted to integer value
| From: | lars at textalk dot se | Date: | Fri, 11 Jun 1999 16:18:26 +0000 |
| Subject: | Bug #1528: Sometimes array element is converted to integer value | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-6825@lists.php.net to get a copy of this message | ||
From: lars@textalk.se
Operating system: Linux Redhat 5.2 kernel 2.0.36
PHP version: 3.0.9
PHP Bug Type: Misbehaving function
Bug description: Sometimes array element is converted to integer value
I noticed the following strange problem in 3.0.5. The problem shows up
randomly, approx 95 % of the time it works as it should, but
sometimes it does not. After upgrade to 3.0.9 the problem is still
there but not as often as in 3.0.5 (I think, this may be wrong).
I have included a script that reproduces the error and two printouts
of the script execution, one when the error is present and one when
everything went allright.
Apache version is 1.3.3 with SSL+SSLeay-0.9.0b and auth-mysql 2.0, php as
a static module.
My php configure line (for php 3.0.9, 3.0.5 was configured without the --without-pcre-rege option):
./configure --with-mysql=/usr/local/mysql
--with-apache=../apache_1.3.3 --with-gd
--without-pcre-regex --enable-track-vars
Here is the script that reproduces the error (printout is included below):
<?php
$currency = 1;
$exrate = array( 0.658, 4.3, 1.22, 4.6, 0.9, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 );
$row = array( 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
$round = 1000;
# convert to selected currency
$row[7] *= 1000; # E
$row[11] *= 1000; # GR
$row[16] *= 1000; # P
if ($currency>0) {
for($i=0;$i<15;$i++) {
$kurs = $exrate[$i];
if ( $kurs <> 1.0) {
print $row[$i+3];
print " $exrate[$i] $round ";
$row[$i+3] = $round * round( $row[$i+3]*$kurs/$round );
print $row[$i+3];
print "<br>\n";
} else {
print "<B><FONT COLOR=\"Red\">extrate=1, i=$i kurs=$kurs
exrate[i] = $exrate[$i]</FONT> THIS IS A BUG BECAUSE exrate[] is never
1</B><br>\n";
}
if ($row[$i+3]>0) {
${"cf".$i}=1;
}
}
} else {
print "<!-- No currency selected -->\n";
}
?>
Printout when the error is present (look at column number 2, every value is converted to integer):
1 0 1000 0
2 4 1000 0 (NOTE: the secound column should be 4.3)
extrate=1, i=2 kurs=1 exrate[i] = 1 THIS IS A BUG BECAUSE exrate[] (and kurs) is never 1, it is 1.22
when i=2
4 4 1000 0
5000 0 1000 0
6 5 1000 0
7 6 1000 0
8 7 1000 0
9000 8 1000 72000
10 9 1000 0
11 10 1000 0
12 11 1000 0
13 12 1000 0
14000 13 1000 182000
15 14 1000 0
Printout when it works:
1 0.658 1000 0
2 4.3 1000 0
3 1.22 1000 0
4 4.6 1000 0
5000 0.9 1000 4000
6 5 1000 0
7 6 1000 0
8 7 1000 0
9000 8 1000 72000
10 9 1000 0
11 10 1000 0
12 11 1000 0
13 12 1000 0
14000 13 1000 182000
15 14 1000 0
/ Lars Gustavsson