ZF-9519: Zend_Currency::setValue() fails when value param is scalar and currency param passed

Issue Type: Bug Created: 2010-03-23T11:12:31.000+0000 Last Updated: 2010-03-23T14:13:20.000+0000 Status: Resolved Fix version(s): - 1.10.3 (01/Apr/10)

Reporter: Sergey Kolosov (m17) Assignee: Thomas Weidner (thomas) Tags: - Zend_Currency

Related issues: Attachments:


If the $value param for setValue() is not an instance of Zend_Currency, setValue() call results in exception in Zend_Currency::_checkParams().


<pre class="highlight">
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();


<pre class="highlight">
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:

<pre class="highlight">
$zc->setValue(100, new Zend_Currency('USD', 'ru_RU'));

tested on 1.10.2, r21613


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.

<pre class="highlight">
E:\Dev\_SVN\Checkout\Zend\tests\Zend>phpunit CurrencyTest.php
PHPUnit 3.4.11 by Sebastian Bergmann.


Time: 33 seconds, Memory: 6.25Mb

There was 1 failure:

1) Zend_CurrencyTest::testSetValueWithoutLocale
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@


Tests: 33, Assertions: 149, Failures: 1.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.