Skip to content

Fix PHP 8.0+ compatibility by upgrading PHP-DI to 7.x - #113

Merged
jimmyn merged 2 commits into
masterfrom
fix/php-8-compatibility
Oct 14, 2025
Merged

Fix PHP 8.0+ compatibility by upgrading PHP-DI to 7.x#113
jimmyn merged 2 commits into
masterfrom
fix/php-8-compatibility

Conversation

@jimmyn

@jimmyn jimmyn commented Oct 14, 2025

Copy link
Copy Markdown
Collaborator

Summary

Fixes fatal error on PHP 8.x caused by PHP-DI 6.4.0 incompatibility with PSR-11 Container interface.

Customer reported error on PHP 8.1.33:

PHP Fatal error: Declaration of DI\Container::has(name) must be compatible with Psr::has(stringid): bool

Changes

  • ⬆️ PHP-DI: 6.4.0 → 7.1.1 (PSR-11 2.0 compatible)
  • ⬆️ PSR Container: 1.1.2 → 2.0.2
  • ⬆️ PHP Requirement: ^7.4 → ^8.0
  • Removed: php-di/phpdoc-reader (no longer needed in v7)
  • 📝 Updated: Plugin headers, readme, developer docs to PHP 8.0
  • 🔧 Updated: GitHub Actions CI to use PHP 8.0
  • 🐛 Fixed: PHPStan bootstrap - added Woocommerce_Gateway_Monei stub

Compatibility Analysis

No code changes required - all existing DI usage patterns compatible:

  • autowire() - ✅ Works
  • create() - ✅ Works
  • get() - ✅ Works
  • factory() - ✅ Works
  • No @Inject annotations found (would require migration to #[Inject])

Breaking Change

⚠️ PHP 7.4 users cannot upgrade to this version

Justification:

  • PHP 7.4 EOL: November 2022 (3+ years ago)
  • PHP 8.0 released: November 2020 (stable for 5 years)
  • WordPress 6.8 officially supports PHP 8.0-8.3
  • Most hosting providers default to PHP 8.0+
  • Customer experiencing this error has PHP 8.1.33

Test Plan

  • Composer dependencies install without errors
  • PHPStan passes (no type errors)
  • Coderabbit review completed (no issues)
  • Plugin activates without fatal errors on PHP 8.0
  • Plugin activates without fatal errors on PHP 8.1
  • Plugin activates without fatal errors on PHP 8.2
  • Plugin activates without fatal errors on PHP 8.3
  • Payment methods display correctly
  • Checkout works with all payment methods

Files Changed

  • composer.json - PHP & PHP-DI version requirements
  • composer.lock - Dependency lockfile
  • woocommerce-gateway-monei.php - Plugin header
  • readme.txt - WordPress.org readme
  • README.md - GitHub readme
  • DEVELOPER.md - Developer documentation
  • .github/workflows/code-quality.yml - CI PHP version
  • tests/phpstan-bootstrap.php - PHPStan mock class

Summary by CodeRabbit

  • Chores

    • Raised minimum PHP requirement to 8.0 across the project.
    • Updated code quality workflow to run on PHP 8.0.
    • Updated package constraints to align with PHP 8.0.
  • Documentation

    • Updated README and public metadata to require PHP 8.0.
    • Revised developer guide with clarified workflow, expanded examples, and a detailed project structure.
  • Tests

    • Added a mock payment gateway class for static analysis bootstrap to improve tooling stability.

- Upgrade PHP-DI from 6.4.0 to 7.1.1
- Update PHP requirement from ^7.4 to ^8.0
- Update composer platform config to PHP 8.0.0
- Update PSR Container from 1.1.2 to 2.0.2
- Remove php-di/phpdoc-reader (no longer needed)
- Update plugin headers to require PHP 8.0
- Update developer documentation to PHP 8.0
- Update GitHub Actions CI to use PHP 8.0
- Add Woocommerce_Gateway_Monei stub to PHPStan bootstrap

This fixes fatal error reported by customer running PHP 8.1.33:
"Declaration of DI\Container::has(name) must be compatible with
Psr::has(stringid): bool"

PHP-DI 6.4.0 is incompatible with PHP 8.0+ due to PSR-11 method
signature mismatches. PHP-DI 7.0+ requires PHP 8.0 minimum and
provides full PHP 8.x compatibility.

No code changes required - existing DI container usage (autowire,
create, get, factory) is fully compatible with PHP-DI 7.

BREAKING CHANGE: PHP 7.4 users cannot upgrade. PHP 8.0 is now the
minimum required version. PHP 7.4 reached end-of-life in November
2022. WordPress 6.8 officially supports PHP 8.0-8.3.
Copilot AI review requested due to automatic review settings October 14, 2025 08:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR upgrades PHP-DI from 6.4.0 to 7.1.1 to resolve a fatal error on PHP 8.x caused by PSR-11 Container interface incompatibility. The upgrade requires bumping the minimum PHP version from 7.4 to 8.0.

Key Changes:

  • Upgraded PHP-DI to version 7.1.1 for PSR-11 2.0 compatibility
  • Updated minimum PHP requirement from 7.4 to 8.0
  • Added PHPStan bootstrap stub for Woocommerce_Gateway_Monei class

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
composer.json Updated PHP requirement to ^8.0 and PHP-DI to ^7.0
woocommerce-gateway-monei.php Updated plugin header to require PHP 8.0
readme.txt Updated PHP requirement and added v7.0.0 changelog
README.md Updated PHP requirement and added v7.0.0 changelog
DEVELOPER.md Updated developer documentation to specify PHP 8.0+ requirement
.github/workflows/code-quality.yml Updated CI workflow to use PHP 8.0
tests/phpstan-bootstrap.php Added mock class for PHPStan analysis

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread readme.txt
Comment thread README.md
@coderabbitai

coderabbitai Bot commented Oct 14, 2025

Copy link
Copy Markdown

Caution

Review failed

The head commit changed during the review from 95f9ffd to d0cf48a.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/php-8-compatibility

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai

coderabbitai Bot commented Oct 14, 2025

Copy link
Copy Markdown

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

The changes update PHP minimum requirements to 8.0 across docs, metadata, CI, and composer constraints; upgrade php-di/php-di to ^7.0; adjust the GitHub Actions workflow to use PHP 8.0; and add a PHPStan bootstrap mock class for Woocommerce_Gateway_Monei. No runtime control flow changes in the plugin code.

Changes

Cohort / File(s) Summary
PHP requirement updates (docs/metadata)
README.md, readme.txt, woocommerce-gateway-monei.php, DEVELOPER.md
Bump displayed/declared minimum PHP version to 8.0 in README, readme, plugin header, and developer docs; doc restructuring/formatting in DEVELOPER.md without functional code changes.
CI workflow PHP version
.github/workflows/code-quality.yml
Change setup-php version from 7.4 to 8.0 for the Code Quality workflow.
Dependency and platform constraints
composer.json
Require PHP ^8.0; set platform PHP to 8.0.0; upgrade php-di/php-di from ^6.4 to ^7.0.
Static analysis bootstrap
tests/phpstan-bootstrap.php
Add mock class Woocommerce_Gateway_Monei with public static function instance() guarded by if (!class_exists(...)) for PHPStan.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the core purpose of the changeset—resolving PHP 8.0+ compatibility by upgrading PHP-DI to version 7.x—which aligns directly with the primary updates in dependencies and CI configuration. It is clear, specific, and concise, allowing reviewers to understand the main change without extraneous detail.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/php-8-compatibility

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
DEVELOPER.md (1)

343-345: Optional: Consider wrapping bare URLs in angle brackets.

Markdownlint flags bare URLs on these lines. While this doesn't affect functionality, you could wrap them in angle brackets for better Markdown compliance:

-   Documentation: https://support.monei.com
-   Email: support@monei.com
-   WordPress.org: https://wordpress.org/plugins/monei/
+   Documentation: <https://support.monei.com>
+   Email: <support@monei.com>
+   WordPress.org: <https://wordpress.org/plugins/monei/>
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb6a045 and d0cf48a.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • .github/workflows/code-quality.yml (1 hunks)
  • DEVELOPER.md (9 hunks)
  • README.md (1 hunks)
  • composer.json (2 hunks)
  • readme.txt (1 hunks)
  • tests/phpstan-bootstrap.php (1 hunks)
  • woocommerce-gateway-monei.php (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
tests/phpstan-bootstrap.php

📄 CodeRabbit inference engine (CLAUDE.md)

Update tests/phpstan-bootstrap.php when introducing new plugin constants, global helpers, or legacy classes used in analysis

Files:

  • tests/phpstan-bootstrap.php
**/*

⚙️ CodeRabbit configuration file

**/*: Generate manual testing checkboxes for the PR. The checkboxes should cover:

  1. Visual verification that the UI renders correctly
  2. Functional testing of user interactions
  3. Edge cases and error states
  4. Cross-browser/device testing if applicable
  5. Integration with related features

Files:

  • tests/phpstan-bootstrap.php
  • README.md
  • readme.txt
  • composer.json
  • DEVELOPER.md
  • woocommerce-gateway-monei.php
🧬 Code graph analysis (1)
tests/phpstan-bootstrap.php (1)
class-woocommerce-gateway-monei.php (2)
  • Woocommerce_Gateway_Monei (21-435)
  • instance (52-58)
🪛 markdownlint-cli2 (0.18.1)
DEVELOPER.md

343-343: Bare URL used

(MD034, no-bare-urls)


344-344: Bare URL used

(MD034, no-bare-urls)


345-345: Bare URL used

(MD034, no-bare-urls)

🔇 Additional comments (8)
README.md (1)

8-8: LGTM! PHP requirement updated consistently.

The minimum PHP requirement metadata has been correctly updated to 8.0, aligning with the dependency upgrades in composer.json and the PHP 8.0+ compatibility fixes.

woocommerce-gateway-monei.php (1)

19-19: LGTM! Plugin header updated correctly.

The PHP requirement in the plugin header has been correctly updated to 8.0, consistent with the broader PHP version upgrade.

readme.txt (1)

7-7: LGTM! WordPress.org metadata updated correctly.

The PHP requirement in readme.txt has been correctly updated to 8.0, ensuring the WordPress.org plugin directory displays accurate compatibility information.

composer.json (2)

34-34: Platform PHP version updated correctly.

The platform PHP version has been correctly updated to 8.0.0, ensuring Composer resolves dependencies compatible with PHP 8.0+.


3-5: Approve PHP 8.0 requirement and DI dependency upgrades.

composer.json and composer.lock have been updated correctly (php-di/php-di 7.1.1, psr/container 2.0.2, platform.php ^8.0). No further changes needed.

Manual testing checklist:

  • Visual verification that the UI renders correctly
  • Functional testing of user interactions
  • Edge cases and error states
  • Cross-browser/device testing if applicable
  • Integration with related features
.github/workflows/code-quality.yml (1)

21-21: LGTM! CI PHP version updated correctly.

The CI workflow now runs on PHP 8.0, ensuring code quality checks are performed on the minimum supported PHP version. This is essential for catching PHP 8.0-specific compatibility issues early.

tests/phpstan-bootstrap.php (1)

236-250: LGTM! PHPStan bootstrap mock class added correctly.

The mock class for Woocommerce_Gateway_Monei has been correctly added to support PHPStan static analysis. The simplified implementation (without the full singleton pattern) is appropriate for a test bootstrap stub, as PHPStan only needs the method signatures and return types.

As per coding guidelines.

DEVELOPER.md (1)

20-20: LGTM! Prerequisites updated to PHP 8.0+.

The PHP prerequisite has been correctly updated from PHP 7.4 to PHP 8.0, consistent with the dependency upgrades and minimum requirements across the project.

@jimmyn
jimmyn merged commit 6cfb6ae into master Oct 14, 2025
5 checks passed
@jimmyn
jimmyn deleted the fix/php-8-compatibility branch October 14, 2025 08:45
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