A PHP implementation of Martin Fowler's Money pattern from Patterns of Enterprise Application Architecture (PoEAA). The library wraps monetary values in an immutable ValueObject that pairs amounts with currencies, preventing common bugs from shared object references. Key features include immutable arithmetic operations (add, subtract) and an allocation method that correctly distributes money across ratios without losing cents due to rounding — for example, splitting 5 cents 70/30 yields 4 and 1 cents rather than fractional values. The open source library is available on GitHub with unit tests demonstrating usage.

3m read timeFrom verraes.net
Post cover image
Table of contents
ImmutabilityAllocationConclusion