Bug #14349 Updated: UTF8_ENCODE conflicts with Type Juggling

From: Date: Fri, 14 Dec 2001 01:31:22 +0000
Subject: Bug #14349 Updated: UTF8_ENCODE conflicts with Type Juggling
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-73640@lists.php.net to get a copy of this message
ID: 14349
Updated by: yohgaki
Reported By: ruud@stress.utwente.nl
Old Status: Open
Status: Closed
Bug Type: XML related
Operating System: Debian GNU/Linux 2.2
PHP Version: 4.0.6
New Comment:

User reported fixed in 4.1.0.
Closed

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

[2001-12-05 13:06:16] ruud@stress.utwente.nl

The problem does not occur "always" and probably not on the first "run" of the
script. So if you just run the script one time, everything might look good. Try to reload the script
many times to see the bug. It seems like a heavy system load exploits the bug.

I reproduced the bug on five different (i386) systems with Linux, running different versions of the
Linux Kernel and Apache, using versions of PHP ranging from 4.0.3 to 4.0.6. The bug occurs on every
system.

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

[2001-12-05 08:47:23] ruud@stress.utwente.nl

Hi,

Please take a look at this PHP script.

<?php

for($j=0; $j<1000; $j++) {
  $result=71.95;
  $price=utf8_encode($result);
  $price = $price * 2.2 / 2.2;
  echo "$price<br>\n";

}

?>

This script should just output 1000x exactly the same but as you can see, the script sometimes
returns "71" instead of "71.95".

Seems to have to do something with type juggling. If we explecitly cast price to a float,
["$price=(float)utf8_encode($result);"] the script returns only the correct value.

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



Edit this bug report at http://bugs.php.net/?id=14349&edit=1



Thread (4 messages)

« previous php.dev (#73640) next »