|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14349 UTF8_ENCODE conflicts with Type Juggling
Submitted: 2001-12-05 08:47 UTC Modified: 2001-12-13 20:31 UTC
From: ruud at stress dot utwente dot nl Assigned:
Status: Closed Package: XML related
PHP Version: 4.0.6 OS: Debian GNU/Linux 2.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: ruud at stress dot utwente dot nl
New email:
PHP Version: OS:


 [2001-12-05 08:47 UTC] ruud at stress dot utwente dot nl

Please take a look at this PHP script.


for($j=0; $j<1000; $j++) {
  $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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-05 13:06 UTC] ruud at stress dot utwente dot 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-13 20:31 UTC]
User reported fixed in 4.1.0.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Mar 27 19:03:38 2023 UTC