Skip to content

Bump minimum PHP requirement to 7.4.12 to avoid covariant return type…#247

Open
vyskoczilova wants to merge 5 commits into
WordPress:trunkfrom
vyskoczilova:trunk
Open

Bump minimum PHP requirement to 7.4.12 to avoid covariant return type…#247
vyskoczilova wants to merge 5 commits into
WordPress:trunkfrom
vyskoczilova:trunk

Conversation

@vyskoczilova

Copy link
Copy Markdown

Summary

Fixes #240 — PHP 7.4.0–7.4.11 have a known PHP engine bug (bug #80126) that causes a fatal error with the covariant return type pattern used throughout this library's DTOs:

Declaration of GenerativeAiResult::fromArray(array $array): GenerativeAiResult must be compatible with WithArrayTransformationInterface::fromArray(array $array): WithArrayTransformationInterface

The bug was fixed in PHP 7.4.12. This PR raises the declared minimum from >=7.4 to >=7.4.12 and adds a runtime guard so the problem surfaces as a clear, actionable message rather than a cryptic fatal error.

Changes

composer.json

  • require.php: >=7.4>=7.4.12
  • config.platform.php: 7.47.4.12

src/polyfills.php

  • Added a trigger_error(E_USER_WARNING) guard at load time for PHP 7.4.0–7.4.11. This file is autoloaded via Composer's files mechanism, so the warning fires on the very first request — before any DTO class is loaded and before a cryptic fatal can occur.

README.md

  • Added a Requirements section listing PHP 7.4.12+ with a link to the PHP bug report.

CONTRIBUTING.md

  • Updated the PHP Compatibility section to state 7.4.12 as the minimum and explain why.

AGENTS.md

  • Updated the key constraints list to reflect 7.4.12.

phpcs.xml.dist

  • Updated the inline comment to reference 7.4.12+. The testVersion value stays 7.4- because PHPCompatibility does not support patch-level version filtering — this is correct and intentional.

Notes

  • No logic changes, no API surface changes.
  • All 1088 unit tests pass.
  • The trigger_error approach (rather than throwing an exception) is deliberate: it fires early without hard-aborting, matches the WordPress-agnostic nature of the library, and follows the same conditional-check pattern already used in polyfills.php.

Closes #240


https://profiles.wordpress.org/vyskoczilova/

… fatal (#1)

PHP 7.4.0–7.4.11 have a known engine bug (https://bugs.php.net/bug.php?id=80126)
that causes a fatal error when a class method returns a more specific type than
its interface declares. The DTO inheritance pattern used throughout this project
(e.g. GenerativeAiResult::fromArray returning GenerativeAiResult instead of
WithArrayTransformationInterface) triggers this exact bug on affected patch
releases. The bug was fixed in PHP 7.4.12.

Updates composer.json require and platform config, CONTRIBUTING.md compatibility
note, and AGENTS.md key constraints to reflect 7.4.12 as the true minimum.

Fixes WordPress#240

Co-authored-by: Claude <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @claude, @sensahin.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: claude, sensahin.

Co-authored-by: vyskoczilova <vyskoczilova@git.wordpress.org>
Co-authored-by: felixarntz <flixos90@git.wordpress.org>
Co-authored-by: johnbillion <johnbillion@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

claude added 3 commits June 4, 2026 09:33
Regenerates the content-hash after bumping config.platform.php from 7.4
to 7.4.12 in composer.json, which caused the lock file to be flagged as
out of date in CI.

https://claude.ai/code/session_0196NorwZgGmwBVudD4Q3eQz
Corrects the content-hash after bumping config.platform.php from 7.4 to
7.4.12. The previous hash was computed with extra config fields; this one
matches Composer's Locker::getContentHash() exactly (only config.platform
is included). Passes `composer validate` locally.

https://claude.ai/code/session_0196NorwZgGmwBVudD4Q3eQz
Updates the baked-in platform and platform-overrides values in
composer.lock to match the new >=7.4.12 requirement in composer.json.
The old lock file had platform-overrides.php: 7.4, causing
`composer install` to fail because 7.4 < 7.4.12.

https://claude.ai/code/session_0196NorwZgGmwBVudD4Q3eQz
@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.12%. Comparing base (99a65e8) to head (ec55a84).

Additional details and impacted files
@@            Coverage Diff            @@
##              trunk     #247   +/-   ##
=========================================
  Coverage     88.12%   88.12%           
  Complexity     1213     1213           
=========================================
  Files            60       60           
  Lines          3934     3934           
=========================================
  Hits           3467     3467           
  Misses          467      467           
Flag Coverage Δ
unit 88.12% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Since composer.json enforces >=7.4.12, PHP_VERSION_ID is always >=70412
at runtime, making the 7.4.0-7.4.11 trigger_error check unreachable.
PHPStan correctly flags both comparisons as always-false/always-true.
The composer.json minimum version requirement is sufficient protection.

https://claude.ai/code/session_0196NorwZgGmwBVudD4Q3eQz
@vyskoczilova

Copy link
Copy Markdown
Author

Done, sorry for the mess with the composer.lock, but fixed now.

@felixarntz felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@vyskoczilova Thank you for the PR!

Generally, this seems reasonable to me, but we need to consider how this affects WordPress Core, which relies on this package.

@johnbillion What is the exact minimum PHP version supported by WordPress now? is it 7.4 exactly? or any particular patch version of it?

@johnbillion

Copy link
Copy Markdown
Member

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.

PHP 7.4.0-7.4.11 fatal due to covariant return type bug in php-ai-client DTOs

4 participants