Skip to content

Add PHP 8.4 and PHP 8.5 compatibility#26

Open
SamueleMartini wants to merge 1 commit intomage-os:mainfrom
SamueleMartini:php85-compatibility
Open

Add PHP 8.4 and PHP 8.5 compatibility#26
SamueleMartini wants to merge 1 commit intomage-os:mainfrom
SamueleMartini:php85-compatibility

Conversation

@SamueleMartini
Copy link
Copy Markdown

@SamueleMartini SamueleMartini commented Apr 21, 2026

Summary

This PR adds PHP 8.4 and PHP 8.5 compatibility to MageOS_ThemeOptimization while keeping the module working on PHP 8.1/8.2/8.3.

Current last tag: 2.2.0. Suggested next tag: 2.3.0 (backwards-compatible additions/changes only).

cc @rhoerr

Changes

  • Added declare(strict_types=1) to every PHP class in the module (previously missing on ViewTransitions, SpeculationRules, UpdateSpeculationRulesConfigPathPatch).
  • Added explicit return types to every method, including Setup\Patch\Data\UpdateSpeculationRulesConfigPathPatch::apply(), getAliases() and getDependencies(), so subclasses and static analysis don't fall back on the implicit-nullable/void deprecations introduced in PHP 8.4.
  • Typed class constants (const string, const array) on ViewTransitions, SpeculationRules, BfCache and the Http plugin to take advantage of PHP 8.3+ typed constants.
  • Typed nullable parameters explicitly (e.g. int|string|null $store in Http::getConfig()) so PHP 8.4's "implicit nullable parameter is deprecated" warning doesn't trigger.
  • afterSetNoCacheHeaders now uses mixed $result / mixed return type instead of an untyped parameter.
  • Replaced strpos($theme->getCode(), 'Hyva/') === 0 with str_starts_with() in SpeculationRules::isHyva().
  • Constructor-promoted properties are now protected (instead of private) on every class, and private helpers (isHyva, isRequestCacheable, isRequestInExcludePatterns, parseExcludePatterns, isEnabled, getConfig) are also protected, so downstream modules/themes can extend the behavior without plugins.
  • Minor refactors: array_map in place of manual foreach-and-append loops in SpeculationRules::getExcludedExtensions() / getExcludedSelectors(); unset($pattern) after the foreach-by-reference loop in getExcludedPaths(); re-imported Magento\Framework\App\Response\Http as ResponseHttp in the plugin so the fully-qualified-name isn't repeated in method signatures.
  • composer.json: added an explicit php constraint ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0.
  • Added a CHANGELOG.md with a 2.3.0 — 2026-04-21 entry.

Backwards compatibility

  • No public method signature was changed; only return types were added where previously missing (always matching the documented @return).
  • DataPatchInterface::apply() doesn't declare a return type in Magento framework (its PHPDoc says @return $this); the concrete apply() now declares : self and return $this, which is covariance-compatible with the interface.
  • Visibility changes are widening only (private -> protected), so no downstream break.

Test plan

  • composer install and module registration on PHP 8.1, 8.3, 8.4 and 8.5.
  • Run the included unit tests (vendor/bin/phpunit Test/Unit) on PHP 8.4 and 8.5.
  • Smoke test in a Magento 2.4.7+ storefront: speculation rules JSON is emitted, view-transitions CSS/JS is rendered, bfcache plugin flips no-store on cacheable responses.
  • Verify no deprecation notices are raised with error_reporting(E_ALL) on PHP 8.4 / 8.5.

Suggested release

Tag 2.3.0 (minor bump — only additive/internal changes, no public API break).

@SamueleMartini SamueleMartini requested review from a team and rhoerr as code owners April 21, 2026 17:06
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.

1 participant