#44156 [Opn->Csd]: money_format treats 0, "", and null differently

From: Date: Fri, 07 Nov 2008 11:56:08 +0000
Subject: #44156 [Opn->Csd]: money_format treats 0, "", and null differently
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-1432@lists.php.net to get a copy of this message
ID: 44156 Updated by: vrana@php.net Reported By: php at displague dot com -Status: Open +Status: Closed Bug Type: Documentation problem Operating System: linux PHP Version: 5.2.5 New Comment: 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). Previous Comments: ------------------------------------------------------------------------ [2008-02-18 18:37:01] 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-02-18 18:32:22] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44156&edit=1

« previous php.doc.bugs (#1432) next »