Skip to content

PHP 8.4 and 8.5 compatibility#62

Merged
rhoerr merged 2 commits into
mage-os:mainfrom
SamueleMartini:php85-compatibility
Apr 30, 2026
Merged

PHP 8.4 and 8.5 compatibility#62
rhoerr merged 2 commits into
mage-os:mainfrom
SamueleMartini:php85-compatibility

Conversation

@SamueleMartini

@SamueleMartini SamueleMartini commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

Replaces #61 (closed due to branch protection preventing updates).

Summary

This PR adds forward-compatibility for PHP 8.4 and PHP 8.5 while keeping PHP 8.2/8.3 support.

The last PHP 8.4 pass (#34) landed in 1.9.0, but a handful of spots still rely on silent null/false coercion that becomes a hard error on PHP 8.5 (where several long-standing deprecations are being promoted to TypeErrors, e.g. passing null to internal string functions, or passing a non-parseable string to DateTime::modify()).

cc @rhoerr @dadolun95 @SamueleMartini — happy to iterate if you want to tag this as 2.1.2 after merge.

Fixes

  • Plugin/Adminhtml{Category,Cms,Product}BeforeSavePlugin: cast the return value of preg_replace() to string before strtolower(). preg_replace can return null on failure, and strtolower(null) is a TypeError on PHP 8.5.
  • Helper/Service::encodePageBuilderHtmlBox: cast DOMDocument::saveHTML() results to string before feeding them to html_entity_decode() / string concatenation. saveHTML() can return false; PHP 8.5 enforces the string parameter of html_entity_decode strictly.
  • Helper/ModuleConfig::getTranslationExpirationDate: cast the retranslation-period scope value to int before building the DateTime::modify() expression. Previously an unset/empty config produced - days, which becomes a DateMalformedStringException on PHP 8.5.
  • Setup/Patch/Data/MigrateConfigPaths: cast the legacy scope value to string before re-encrypting, since EncryptorInterface::encrypt() now requires a strict string on PHP 8.5.
  • Nullable values used as array index: cast to string/int before using as array key to avoid PHP 8.5 null array key deprecation (follow-up to PHP 8.4 and 8.5 compatibility #61 feedback on PHP 8.4 and 8.5 compatibility mage-os-lab/module-widgetkit#13).
  • composer.json: widen the PHP constraint to >=8.2 <8.6 so Composer resolves cleanly on PHP 8.4 and 8.5.

No behavior change on PHP 8.2/8.3 — all casts are no-ops on valid input.

Suggested tag

2.1.2 (patch — backwards compatible bug fixes only).

Test plan

  • php -l on all changed files
  • Manual: translate a category / product / CMS page with a populated url_key / identifier on PHP 8.5
  • Manual: run the translation cron on PHP 8.5 with a valid retranslation period set

@rhoerr rhoerr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@rhoerr rhoerr merged commit 4d60efd into mage-os:main Apr 30, 2026
1 of 3 checks passed
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