ID: 44156 User updated by: php at displague dot com Reported By: php at displague dot com Status: Open Bug Type: Unknown/Other Function Operating System: linux PHP Version: 5.2.5 New Comment:
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 Previous Comments: ------------------------------------------------------------------------ [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