Skip to content

Introduce Currency::zero() factory for Money#825

Merged
frederikbosch merged 1 commit into
moneyphp:masterfrom
ruudk:zero-currency
Apr 30, 2026
Merged

Introduce Currency::zero() factory for Money#825
frederikbosch merged 1 commit into
moneyphp:masterfrom
ruudk:zero-currency

Conversation

@ruudk

@ruudk ruudk commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

This is just a nice Developer Experience improvement:

When building up an amount through calculations, you often start from an empty Money in a known currency. The typical pattern is:

$amount = new Money(0, $currency);
$amount = $amount->add(...);

Since the currency is usually the thing you already have in hand, reading the code flows better when the currency itself produces the zero value:

$amount = $currency->zero()->add(...);

When building up an amount through calculations, you often start
from an empty Money in a known currency. The typical pattern is:

```php
$amount = new Money(0, $currency);
$amount = $amount->add(...);
```

Since the currency is usually the thing you already have in hand,
reading the code flows better when the currency itself produces the
zero value:

```php
$amount = $currency->zero()->add(...);
```
@ruudk

ruudk commented Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

@frederikbosch Ready for review, whenever you have time 🙏

@frederikbosch

frederikbosch commented Apr 30, 2026

Copy link
Copy Markdown
Member

This looks good @ruudk. I very much recognize the pattern you mention in the PR. Therefore I think it is very good addition to the library.

@frederikbosch frederikbosch merged commit b881f93 into moneyphp:master Apr 30, 2026
15 checks passed
@frederikbosch

Copy link
Copy Markdown
Member

I will tag tomorrow.

@ruudk

ruudk commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

Friendly ping 😁

@ruudk ruudk deleted the zero-currency branch May 4, 2026 09:58
@frederikbosch

Copy link
Copy Markdown
Member

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants