php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53775 parseCurrency returns 0 instead of false
Submitted: 2011-01-18 09:56 UTC Modified: 2011-01-18 14:01 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: _coola_ at arcor dot de Assigned:
Status: Not a bug Package: I18N and L10N related
PHP Version: 5.3SVN-2011-01-18 (SVN) OS: win xp
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: _coola_ at arcor dot de
New email:
PHP Version: OS:

 

 [2011-01-18 09:56 UTC] _coola_ at arcor dot de
Description:
------------
Hi! :)

I think i have found a bug in NumberFormatter.
parseCurrency() returns 0 instead of false in the following test script.

Same Problem with parse().

Test script:
---------------
$fmt=new NumberFormatter('de_DE',NumberFormatter::CURRENCY);

$result=$fmt->parseCurrency('aaa',$currency);
//$result=$fmt->parse('aaa');

// results:
var_dump($result);   // float(0)
var_dump($currency); // string(0) "" 

// no errors!!
var_dump($fmt->getErrorCode());                  // int(0)
var_dump($fmt->getErrorMessage());               // string(12) "U_ZERO_ERROR" 
var_dump(intl_is_failure($fmt->getErrorCode())); // bool(false)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-18 10:15 UTC] aharvey@php.net
-Package: Unknown/Other Function +Package: I18N and L10N related
 [2011-01-18 14:01 UTC] iliaa@php.net
-Status: Open +Status: Bogus
 [2011-01-18 14:01 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The parseCurrency() expects the 1st parameter to be a float, when given a string 
PHP automatically casts it to float resulting in 0.
 [2011-01-19 17:24 UTC] _coola_ at arcor dot de
1st parameter has to be a string
http://php.net/manual/en/numberformatter.parsecurrency.php
 [2011-01-25 16:41 UTC] garioch2 at googlemail dot com
I read the bug report and your reply as well.

According to the respective manual page 

"returns the parsed value or FALSE on error" -> I would expect to get FALSE when trying to parse 'aaa' into any available currency and locale (And the one who wrote the bug report too) ^^

Instead it appears that the parseCurrency method just uses the locale to transform the float number it expects in the String-parameter 
And then simply uses float_val() to convert the string to a real float value.

Thus we get 0 (zero) for trying to parse 'aaa'.

But this makes it hard to differentiate between 
a real Zero and a Zero occuring coz of wrong input-data. And I think the FALSE  would really help in the latter case (as in various string-functions like strpos and so on)

thanks for your time!
 [2011-01-26 12:28 UTC] _coola_ at arcor dot de
Correct! That´s the problem. Thank you. :)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 11:01:31 2025 UTC