Caution: The documentation you are viewing is
for an older version of Zend Framework.
You can find the documentation of the current version at:
https://docs.zendframework.com/
Using Zend_Currency - Zend_Currency
The simplest usecase within an application is to use the clients locale. When you create a instance of Zend_Currency without giving any options, your clients locale will be used to set the proper currency.
Example #1 Creating a currency with client settings
Let's assume that your client has set "en_US" as wished language within his browser. In this case Zend_Currency will automatically detect the currency which has to be used.
The created object would now contain the currency "US Dollar" as this is the actual assigned currency for US (United States). It has also other options set, like "$" for the currency sign or "USD" for the abbreviation.
Note: Automatic locale detection does not always work
You should note that this automatic locale detection does not always work properly. The reason for this behaviour is that Zend_Currency must have a locale which includes a region. When the client would only set "en" as locale Zend_Currency would not know which of the more than 30 countries was meant. In this case an exception would be raised.
A client could also omit the locale settings within his browser. This would lead to the problem that your environment settings will be used as fallback and could also lead to an exception.
To prevent the problems with your client you could simply set the wished locale manually.
As within our first example the used currency will be "US Dollar". But now we are no longer dependend on the clients settings.
Zend_Currency also supports the usage of an application-wide locale. You can set a Zend_Locale instance in the registry as shown below. With this notation you can avoid setting the locale manually for each instance when you want to use the same locale throughout the application.
Zend_Currency is also able to work on a given country by using Zend_Locale internally.
Note: Uppercase territories
When you know that you are using a territory, then you should uppercase it. Otherwise you could get an in your eyes false locale in return. For example, when you give "om" then you could expect "ar_OM" to be returned. But in fact it returns "om", as it's also a language.
Therefor always uppercase the input when you know that a territory is meant.