php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #44156 money_format treats 0, "", and null differently
Submitted: 2008-02-18 18:32 UTC Modified: 2008-11-07 11:56 UTC
From: php at displague dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.2.5 OS: linux
Private report: No CVE-ID: None
 [2008-02-18 18:32 UTC] php at displague dot com
Description:
------------
There is an unexpected (or undocumented) aspect of money_format.  When supplied with 0 or null as a value it returns the formatted version of those values.  When an empty string is supplied as the value, null is returned.  Null and '' should be treated the same way in this case.

This behavior may be understandable when a non-numeric string is submitted, but a notice should probably be emitted.  

Reproduce code:
---------------
<?php
ini_set('display_errors',true);
error_reporting(E_ALL & E_STRICT);

foreach(array("0"=>0,"''"=>"",'null'=>null,"'dummy'"=>'dummy',"'2'"=>'2') as $desc=>$value) {
  $mf = money_format("%(n",$value);
  echo "value: $desc\tformat:'".$mf."'\tis_null: ".(string)(int)is_null($mf)."\n";
}


Expected result:
----------------
value: 0	format:'0.00'	is_null: 0
value: ''	format:''	is_null: 1
value: null	format:'0.00'	is_null: 0
value: 'dummy'	format:''	is_null: 1
value: '2'	format:'2.00'	is_null: 0


Actual result:
--------------
value: 0	format:'0.00'	is_null: 0
value: ''	format:'0.00'	is_null: 0
value: null	format:'0.00'	is_null: 0
value: 'dummy'	format:'0.00'	is_null: 0
value: '2'	format:'2.00'	is_null: 0


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-18 18:37 UTC] php at displague dot com
I entered the results in the wrong fields.  It should have read:

Expected result:
--------------
value: 0	format:'0.00'	is_null: 0
value: ''	format:'0.00'	is_null: 0
value: null	format:'0.00'	is_null: 0
value: 'dummy'	format:'0.00'	is_null: 0
value: '2'	format:'2.00'	is_null: 0

Actual result:
----------------
value: 0	format:'0.00'	is_null: 0
value: ''	format:''	is_null: 1
value: null	format:'0.00'	is_null: 0
value: 'dummy'	format:''	is_null: 1
value: '2'	format:'2.00'	is_null: 0
 [2008-11-07 11:56 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"Non-numeric number causes returning NULL and emitting E_WARNING."

P.S. All errors are enabled by error_reporting(E_ALL | E_STRICT), not error_reporting(E_ALL & E_STRICT).

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 22 06:00:03 2025 UTC