|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53667 number_format problem in empty string
Submitted: 2011-01-06 12:59 UTC Modified: 2011-01-06 15:20 UTC
From: diego at agudo dot eti dot br Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 5.3.4 OS: Debian-5
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: diego at agudo dot eti dot br
New email:
PHP Version: OS:


 [2011-01-06 12:59 UTC] diego at agudo dot eti dot br
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:
 $x = "";
 echo "-->". number_format($x);

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);


Expected result:
I hope the developers look fondly and fix this problem. Although trivial, many other applications users can also get this problem.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-06 14:37 UTC]
-Status: Open +Status: Bogus
 [2011-01-06 14:37 UTC]
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);
 [2011-01-06 15:20 UTC] diego at agudo dot eti dot br
I understand, I'm using casting (float), just felt the difference from version 5.2.6 is not necessary to add any kind of casting. I figured it would be interesting to continue this way in future versions.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 20 04:01:28 2024 UTC