ZF-9519: Zend_Currency::setValue() fails when value param is scalar and currency param passed
Description
If the $value param for setValue() is not an instance of Zend_Currency, setValue() call results in exception in Zend_Currency::_checkParams().
Code:
class ExchangerService implements Zend_Currency_CurrencyInterface
{
public function getRate($from, $to)
{
if ('RUB' == $from && 'USD' == $to)
return 0.033333;
elseif ('USD' == $from && 'RUB' == $to)
return 30;
return 1;
}
}
$zc = new Zend_Currency('RUB', 'ru_RU');
$zc->setService(new ExchangerService());
$zc->setValue(100, 'USD');
echo $zc->toCurrency();
Result:
Zend_Currency_Exception: No region found within the locale ''
thrown in E:\WWW\libs\Zend\Currency.php on line 310
Stack trace:
#0 E:\WWW\libs\Zend\Currency.php(366): Zend_Currency->_checkParams('USD', NULL)
#1 E:\WWW\libs\Zend\Currency.php(752): Zend_Currency->getShortName('USD')
#2 E:\WWW\libs\Zend\Currency.php(593): Zend_Currency->_exchangeCurrency(100, 'USD')
#3 E:\SomeSourceFile.php(8): Zend_Currency->setValue(100, 'USD')
The same exception for the following code:
$zc->setValue(100, new Zend_Currency('USD', 'ru_RU'));
tested on 1.10.2, r21613
Comments
Posted by Thomas Weidner (thomas) on 2010-03-23T13:18:44.000+0000
Fixed with r21616
Posted by Sergey Kolosov (m17) on 2010-03-23T14:13:19.000+0000
short name assertion in test is erroneous, setValue shouldn't change currency, it's just set numeric value, so short name should stay unchanged — RUB.