Why Currency?
Handling money with PHP float values and ad-hoc number_format() calls breaks silently as soon as a project introduces multi-currency pricing, deposits, refunds, tax splits, or historical accounting reports.
Ad-Hoc Float Math vs. Currency
Section titled “Ad-Hoc Float Math vs. Currency”| Problem | Raw PHP float & Custom Scripts |
ProcessWire Currency |
|---|---|---|
Rounding drift (0.1 + 0.2) |
Binary floating-point inaccuracies accumulate across line items | Integer minor units (Money) + exact DecimalMath (ext-bcmath), rejecting float in Money::fromMajor() |
| Splitting deposits or taxes | Naive division drops or duplicates 1 cent | Largest-remainder Money::allocate() guarantees array_sum($parts) === $amountMinor |
| Exchange rate sourcing | Hardcoded multipliers or fragile cron scripts | Built-in EcbProvider, TcmbProvider, ManualProvider, plus ExchangeRateProviderInterface and SyncExchangeRatesTask |
| Historical invoice accuracy | Overwriting a rate breaks past order conversions | Locked currency-rate-history snapshots queried by effectiveDate (findRateOnOrBefore, findCrossRateOnOrBefore) |
| Safe base currency changes | Manual SQL updates risk corrupting sibling rates | Atomic setBaseCurrency() under CurrencyWriteLock and Entries::saveMany() rebases every sibling rate safely |
| SSRF & cookie security | Unpinned file_get_contents() and unsafe cookie names |
WireHttpTransport pins resolved public IPs (CURLOPT_RESOLVE, 5 MiB cap) and VisitorCurrencyResolver blocks reserved session/CSRF cookie names |
Shared Foundation for Commerce & Payments
Section titled “Shared Foundation for Commerce & Payments”Upper-layer modules including Payments, Forms, Packages, Commerce, and Charter depend on Currency for ISO 4217 validation, currencyOptions(), resolveAllowedCurrencies(), and minor-unit precision. Configuring currencies once in Setup -> Currencies keeps your entire ProcessWire stack aligned.