php.net |  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
 [2001-12-05 08:47 UTC] ruud at stress dot utwente dot 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] yohgaki@php.net
User reported fixed in 4.1.0.
Closed
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Dec 08 06:03:33 2021 UTC