Skip to content

fix: mpdf psr-http-message-shim v2 compatibility#782

Merged
superdav42 merged 1 commit intomainfrom
fix/mpdf-psr-http-message-v2-compat
Apr 10, 2026
Merged

fix: mpdf psr-http-message-shim v2 compatibility#782
superdav42 merged 1 commit intomainfrom
fix/mpdf-psr-http-message-v2-compat

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

@superdav42 superdav42 commented Apr 10, 2026

Summary

  • Fixes PHP Fatal error when plugin-check (or any plugin bundling psr/http-message v2) loads before mpdf's shim classes
  • Extends the existing mpdf-psr-http-message-shim-php8-compat.patch to cover all 4 shim files (Request, Response, Stream, Uri) — previously only Request.php was patched
  • Adds return type declarations, parameter type hints, and fixes bare return; statements for nullable return types
  • Fixes patch file paths (a/src/... instead of a/vendor/...) so cweagans/composer-patches applies them correctly

Root cause

The plugin-check WordPress plugin bundles psr/http-message v2.0 which declares return types on all interface methods (e.g. getRequestTarget(): string). When its autoloader loads the v2 interface before mpdf, the shim classes fail with:

PHP Fatal error: Declaration of Mpdf\PsrHttpMessageShim\Request::getRequestTarget() must be compatible with Psr\Http\Message\RequestInterface::getRequestTarget(): string

Test plan

  • Run composer install on a clean vendor — verify patch applies without errors
  • Activate plugin-check alongside Ultimate Multisite — verify no PHP fatal
  • Generate a PDF invoice — verify mpdf still works correctly

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Updated HTTP message interface implementations with explicit type declarations on method signatures for enhanced code robustness and stability.

…bility

The plugin-check WordPress plugin bundles psr/http-message v2.0 which
adds return type declarations to all interface methods. When loaded
before mpdf, PHP fatals because the shim classes implement the v2
interface without matching return types.

The previous patch only covered Request.php. This extends it to all four
shim files (Request, Response, Stream, Uri) with proper return types,
parameter type hints, and bare return fixes for nullable returns.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

This patch adds strict PHP type declarations to PSR HTTP message shim classes (Request, Response, Stream, Uri). All public methods now have explicit return types and typed parameters for PHP 8+ compatibility, with the same functional behavior preserved.

Changes

Cohort / File(s) Summary
PSR HTTP Message Shim Type Declarations
patches/mpdf-psr-http-message-shim-php8-compat.patch (affecting Request.php, Response.php, Stream.php, Uri.php)
Added strict return type and parameter type hints across all public methods in PSR-7 interface implementations. Request and Response classes now declare return types (string, int, array, bool, interface types) and typed parameters. Stream class adds comprehensive type hints including void, ?int, int, bool returns and typed parameters; detach() explicitly returns null instead of implicit return. Uri class adds return/parameter types for all accessors and mutators with proper nullable hints (e.g., ?int for port).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

Poem

🐰 Whiskers twitching with delight,
Types declared, strict and tight!
PSR messages now align,
With PHP 8's design so fine—
Safe and certain, oh what bliss!

🚥 Pre-merge checks | ✅ 3
✅ 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 directly and accurately describes the main change: adding PHP 8 type compatibility to mpdf's PSR HTTP message shim to fix v2 compatibility issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mpdf-psr-http-message-v2-compat

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
patches/mpdf-psr-http-message-shim-php8-compat.patch (1)

1-503: Please add an autoload-order regression for this patch.

This failure mode only appears when the PSR v2 interfaces are loaded before the shim, so a small integration check around that ordering would make this fix much harder to regress on the next vendor update.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@patches/mpdf-psr-http-message-shim-php8-compat.patch` around lines 1 - 503,
Add an autoload-order regression test that reproduces the failure when PSR v2
interfaces are loaded before the shim: write an integration test that first
ensures the PSR interfaces (e.g. \Psr\Http\Message\RequestInterface,
\Psr\Http\Message\ResponseInterface, \Psr\Http\Message\StreamInterface,
\Psr\Http\Message\UriInterface) are present/loaded, then require the shim (the
patched classes Request, Response, Stream, Uri) and assert the shim classes
correctly implement those interfaces and expose the fixed signatures by
instantiating Request/Response/Stream/Uri and checking key behaviors (e.g.
Request implements RequestInterface and getMethod() returns a string, Response
implements ResponseInterface and getStatusCode() returns an int,
Stream::getSize() returns ?int, Uri::getPort() returns ?int); fail the test if
any implementation or return-type behavior differs to prevent regressions when
autoload order changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@patches/mpdf-psr-http-message-shim-php8-compat.patch`:
- Around line 1-503: Add an autoload-order regression test that reproduces the
failure when PSR v2 interfaces are loaded before the shim: write an integration
test that first ensures the PSR interfaces (e.g.
\Psr\Http\Message\RequestInterface, \Psr\Http\Message\ResponseInterface,
\Psr\Http\Message\StreamInterface, \Psr\Http\Message\UriInterface) are
present/loaded, then require the shim (the patched classes Request, Response,
Stream, Uri) and assert the shim classes correctly implement those interfaces
and expose the fixed signatures by instantiating Request/Response/Stream/Uri and
checking key behaviors (e.g. Request implements RequestInterface and getMethod()
returns a string, Response implements ResponseInterface and getStatusCode()
returns an int, Stream::getSize() returns ?int, Uri::getPort() returns ?int);
fail the test if any implementation or return-type behavior differs to prevent
regressions when autoload order changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d39a4f72-0079-4ce1-bfb9-d66942a0b226

📥 Commits

Reviewing files that changed from the base of the PR and between 4295272 and 43b22e2.

📒 Files selected for processing (1)
  • patches/mpdf-psr-http-message-shim-php8-compat.patch

@superdav42 superdav42 merged commit 6b105db into main Apr 10, 2026
11 checks passed
@superdav42
Copy link
Copy Markdown
Collaborator Author

Summary

  • Fixes PHP Fatal error when plugin-check (or any plugin bundling psr/http-message v2) loads before mpdf's shim classes
  • Extends the existing mpdf-psr-http-message-shim-php8-compat.patch to cover all 4 shim files (Request, Response, Stream, Uri) — previously only Request.php was patched
  • Adds return type declarations, parameter type hints, and fixes bare return; statements for nullable return types
  • Fixes patch file paths (a/src/... instead of a/vendor/...) so cweagans/composer-patches applies them correctly

Root cause

The plugin-check WordPress plugin bundles psr/http-message v2.0 which declares return types on all interface methods (e.g. getRequestTarget(): string). When its autoloader loads the v2 interface before mpdf, the shim classes fail with:

PHP Fatal error: Declaration of Mpdf\PsrHttpMessageShim\Request::getRequestTarget() must be compatible with Psr\Http\Message\RequestInterface::getRequestTarget(): string

Test plan

  • Run composer install on a clean vendor — verify patch applies without errors
  • Activate plugin-check alongside Ultimate Multisite — verify no PHP fatal
  • Generate a PDF invoice — verify mpdf still works correctly
    🤖 Generated with Claude Code

Merged via PR #782 to main.
Merged by deterministic merge pass (pulse-wrapper.sh).


aidevops.sh v3.6.235 spent 6m on this as a headless bash routine.

@github-actions
Copy link
Copy Markdown

Performance Test Results

Performance test results for 5758967 are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 41 37.78 MB 806.50 ms (-54.50 ms / -7% ) 155.00 ms (-4.50 ms / -3% ) 1022.00 ms (-24.50 ms / -2% ) 1942.00 ms (-52.00 ms / -3% ) 1850.05 ms (-62.90 ms / -3% ) 87.40 ms
1 56 49.02 MB 902.00 ms 140.50 ms 1040.00 ms (-22.00 ms / -2% ) 1972.00 ms (-66.00 ms / -3% ) 1893.60 ms (-66.40 ms / -4% ) 80.15 ms

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