PHPackages                             elegant-bro/money - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. elegant-bro/money

ActiveLibrary[Payment Processing](/categories/payments)

elegant-bro/money
=================

0.3.6(3y ago)32.0k1[2 PRs](https://github.com/elegant-bro/money/pulls)MITPHPPHP &gt;=7.3

Since Jan 7Pushed 3y ago2 watchersCompare

[ Source](https://github.com/elegant-bro/money)[ Packagist](https://packagist.org/packages/elegant-bro/money)[ RSS](/packages/elegant-bro-money/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (7)Versions (14)Used By (0)

[![Latest Version](https://camo.githubusercontent.com/a9e83febdd015091e181aa25ba64b87c8813b934ed4c557c3f93ed13efdcf7d4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f656c6567616e742d62726f2f6d6f6e65792e737667)](https://github.com/elegant-bro/money/releases)[![Build Status](https://camo.githubusercontent.com/77434df21bb5f00b10fe960989eb1cef485075d6446cb4b09454d12019eed0dd/68747470733a2f2f7472617669732d63692e636f6d2f656c6567616e742d62726f2f6d6f6e65792e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/elegant-bro/money)[![Coverage Status](https://camo.githubusercontent.com/f65fea84054005ea2a560f0a20624cbde9b476cf238776e0885074d187d1954c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f656c6567616e742d62726f2f6d6f6e65792f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/elegant-bro/money?branch=master)

Elegant money implementation
============================

[](#elegant-money-implementation)

This library provides classes for money manipulation using a pure object-oriented approach.

Yet another PHP-money, why?
---------------------------

[](#yet-another-php-money-why)

Why did we make yet another PHP-library for money? After all, there are:

-
-
-

But, there are disadvantages to using it in pure object-oriented development.

- There are no interfaces — we can't create an object that will represent money itself.
- All existed implementations are classes with hundreds loc and dozens of methods like `add`, `sub`, `divide`, `compare` etc., which are essentially procedural style.
- We can't add new functionality as there are no interfaces, and most implementations are final.
- Eager execution — all calculations happen in construct-time as constructor's arguments should be evaluated.
- Existed libraries hide the scale, the only thing we can control is a rounding method.

Our solution
------------

[](#our-solution)

- We have the `Money` interface! This implementation is not procedural DTO.
- There is no hundreds-lines class with tens of methods. Every operation is an object that implements the `Money` interface.
- Lazy execution: you can construct complex expressions without immediate calculations.
- Explicit scale to avoid ambiguous results.

The presence of the interface allows you to make different classes. For example, you can easily implement `UserBalance`that takes data from a database or some API or even from a file.

```
