php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1528 Sometimes array element is converted to integer value
Submitted: 1999-06-11 12:18 UTC Modified: 1999-11-12 11:39 UTC
From: lars at textalk dot se Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.9 OS: Linux Redhat 5.2 kernel 2.0.36
Private report: No CVE-ID: None
 [1999-06-11 12:18 UTC] lars at textalk dot se
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




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-06-20 21:02 UTC] jim at cvs dot php dot net
We need a repeatable example of the error to track this down.
 [1999-06-21 03:58 UTC] lars at textalk dot se
An example was included. Does this mean that you can't
repeat the problem with my example? (this could indicate 
that the problem is my server and not php). 

My example was included with my bug report and can also
be found here:

http://marvin.textalk.com/~lars/phpbug.phtml

Note that the problem does not occur every time the page is loaded,
most of the time it works perfectly, sometimes it does not!

You probably have to reload this URL many times before the error
shows up!

/ Lars

 [1999-11-12 11:39 UTC] joey at cvs dot php dot net
PHP 3.0.9
Debian Linux lernel 2.2.5

I ran through the sample script 400 times, could not duplicate the error.
Marking as closed, unless more info comes in


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 14:00:02 2026 UTC