note 99179 deleted from function.number-format by danbrown
| From: | danbrown@php.net | Date: | Sun, 01 Aug 2010 14:03:32 +0000 |
| Subject: | note 99179 deleted from function.number-format by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171304@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
This is a bug from 5.3.2, not sure if it was fixed in 5.3.3
number_format fails to return anything when a keyed array is passed to it to be formatted.
Warning: number_format() expects parameter 1 to be double, object given in .... on line ....
<?php
$array['test'] = 10567987.23;
function num_format($num, $rnd = 2) {
$num = trim($num);
return number_format($num,$rnd,'.',',');
}
//always dies silently with warning if enabled
echo number_format($array['test'],2,'.',',')."<br
/>\n";
//works fine in php 5.3.2
echo num_format($array['test'])."<br />\n";
?>
Added a trim() and number_format handles it fine in the short quick-fix function....
So, number_format is adding a whitespace around the number passed to it from an array key...