Bug #53667 [Opn->Bgs]: number_format problem in empty string
| From: | kalle@php.net | Date: | Thu, 06 Jan 2011 13:37:59 +0000 |
| Subject: | Bug #53667 [Opn->Bgs]: number_format problem in empty string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-157667@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53667&edit=1
ID: 53667
Updated by: kalle@php.net
Reported by: diego at agudo dot eti dot br
Summary: number_format problem in empty string
-Status: Open
+Status: Bogus
Type: Bug
Package: *Math Functions
Operating System: Debian-5
PHP Version: 5.3.4
Block user comment: N
Private report: N
New Comment:
This is global for the parameter parsing API thats used across all
functions within the PHP core. The thing is that "" cannot be converted
to a double as there is no value, whereas "0" can be converted to a
numeric value, "0" => 0 => (double) 0.
You should validate the input before sending it to the function, or
alternatively forcing type casting which is an ugly hack but it fixes
the problem for you:
number_format((double) $x);
Previous Comments:
------------------------------------------------------------------------
[2011-01-06 12:59:24] diego at agudo dot eti dot br
Description:
------------
The problem occurs in version 5.3.4, the same situation does not create
problems in version 5.2.6.
Passing an empty string as a parameter is generated an error that the
parameter must be of type double the problem does not occur if the same
string is not empty.
Test script:
---------------
Example 01:
Code:
<?
$x = "";
echo "-->". number_format($x);
?>
Output:
Warning: number_format() expects parameter 1 to be double, string given
in /www/htdocs/test.php on line 5
-->
Example 02:
<?
$x = "0";
echo "-->". number_format($x);
?>
Output:
-->0
Expected result:
----------------
I hope the developers look fondly and fix this problem. Although
trivial, many other applications users can also get this problem.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53667&edit=1