Skip to content

Fix PHP 8.1+ deprecations on the payment path (number_format, jsonSerialize)#1411

Open
rcoenen wants to merge 7 commits into
mollie:release-6.4.4from
rcoenen:fix/php81-deprecations
Open

Fix PHP 8.1+ deprecations on the payment path (number_format, jsonSerialize)#1411
rcoenen wants to merge 7 commits into
mollie:release-6.4.4from
rcoenen:fix/php81-deprecations

Conversation

@rcoenen

@rcoenen rcoenen commented Jun 11, 2026

Copy link
Copy Markdown

Fixes the PHP 8.1+ deprecation notices reported in #1410. They surface on the payment/checkout path on PHP 8.3 and become a fatal TypeError on PHP 9, so this is a forward-compatibility fix (no behaviour change on supported PHP versions).

Changes

1. number_format(null)src/Utility/TextFormatUtility.php

formatNumber() can receive a null $unitPrice, and number_format(null, …) is deprecated since PHP 8.1 and a TypeError on PHP 9. Casting to float (null → 0.0) preserves the current output — number_format(null, …) already yields "0" — with no behaviour change.

2. jsonSerialize() return type — 4 DTOs

JsonSerializable::jsonSerialize() is declared : mixed since PHP 8.1, so implementations with no declared return type emit a deprecation. Added #[\ReturnTypeWillChange] (parsed as a comment on PHP 7.x, recognised on 8.1+) to the four implementations that declare no return type:

The four DTOs that already declare : array (OrderLine, OrderData, PaymentData, PaymentLine) are covariant with mixed and were left untouched.

Notes

  • #[\ReturnTypeWillChange] was chosen over a : mixed return type because composer.json declares no php floor (the module still targets PHP 7.x), and : mixed requires PHP 8.0+.
  • It may be worth separately investigating why a null amount reaches formatNumber() in the payment flow, but the cast removes the deprecation/TypeError regardless.
  • php -l is clean on all changed files.

Refs #1410

🤖 Generated with Claude Code

dependabot Bot and others added 7 commits April 14, 2026 10:10
Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.2 to 1.16.0.
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](follow-redirects/follow-redirects@v1.15.2...v1.16.0)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-version: 1.16.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.4 to 1.16.0.
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](follow-redirects/follow-redirects@v1.15.4...v1.16.0)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-version: 1.16.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [postcss](https://github.com/postcss/postcss) from 8.4.38 to 8.5.10.
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](postcss/postcss@8.4.38...8.5.10)

---
updated-dependencies:
- dependency-name: postcss
  dependency-version: 8.5.10
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
…ews/assets/follow-redirects-1.16.0

Bump follow-redirects from 1.15.2 to 1.16.0 in /views/assets
…llow-redirects-1.16.0

Bump follow-redirects from 1.15.4 to 1.16.0
…stcss-8.5.10

Bump postcss from 8.4.38 to 8.5.10
…ialize)

These surface on PHP 8.3 and become a fatal TypeError on PHP 9 (see mollie#1410).

- TextFormatUtility::formatNumber: cast $unitPrice to float so a null amount
  no longer triggers the number_format() deprecation. Output is unchanged
  (number_format(null, ...) already yields "0").
- Add #[\ReturnTypeWillChange] to the four JsonSerializable implementations
  that declare no return type (Object/Payment, Object/Company, Errors/Error,
  ApplePay/Carrier/Carrier). The four DTOs that already return ': array'
  (OrderLine, OrderData, PaymentData, PaymentLine) are covariant with mixed
  and left untouched. The attribute keeps PHP 7.x compatibility.

Refs mollie#1410

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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