ZF-7864: Zend_Currency::toCurrency() ignores option param "currency"


I always use an instance of Zend_Currency to display prices etc. Now I ran into a bug after upgrading from 1.7.8 to 1.9.2 - the toCurrency method ignores the currency value in the option array. Here is a small test I used:

$value = '';
$currencyObject = new Zend_Currency('de_DE');
$value = $currencyObject->toCurrency(2.3, array('currency' => 'USD', 'precision' => 4));
Zend_Debug::dump($value); // prints "2,3000 €" - expected "2,3000 $"

$value = '';
$currencyObject = new Zend_Currency('USD', 'de_DE');
$value = $currencyObject->toCurrency(2.3, array('precision' => 4));
Zend_Debug::dump($value); // prints "2,3000 $" as expected

The first example is often used, because I cannot know which currency should be used for the customer - so setting the currency while converting is a must have for me. If I see it right, the bug depends on getSymbol() which results in an error if no locale is given. I will add a patch which corrects the problem for me.


I will add additionally a Unit-Test patch ( I read the "Bughunt day" notification today) so that it does not need to be double-researched. This will take some minutes I think ;) Just wait until I have uploaded it.

Added UnitTest to CurrencyTest.php

Note that this "patch" introduces a new problem and can not be used as is.

Note that your provided example set's another display type at initiation than at output. This leads to the behaviour that the output uses another display that the one you set. If you would set the wished display type then the code would work. This has not changed since ZF 1.7.8.

Fixed with a new feature to automatically detect the wished display type. (r18432)