Skip to content

Script Modules: Guard setAccessible() calls behind PHP < 8.1 check#78137

Merged
ramonjd merged 1 commit into
trunkfrom
fix/reflection-setaccessible-php81
May 11, 2026
Merged

Script Modules: Guard setAccessible() calls behind PHP < 8.1 check#78137
ramonjd merged 1 commit into
trunkfrom
fix/reflection-setaccessible-php81

Conversation

@ramonjd
Copy link
Copy Markdown
Member

@ramonjd ramonjd commented May 11, 2026

What?

Wraps the two ReflectionProperty/ReflectionMethod::setAccessible( true ) calls in lib/compat/wordpress-7.0/script-modules.php with a PHP_VERSION_ID < 80100 guard.

Follow-up to #77214. Fixes #78124.

Why?

As of PHP 8.1, private/protected members are accessible via reflection without calling setAccessible(), so the call is a no-op. PHP 8.5 deprecates it, emitting:

Method ReflectionMethod::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1

…on every editor page load when WP_DEBUG is enabled on WP < 7.0 (where this polyfill runs).

How?

Guards each setAccessible( true ) call behind if ( PHP_VERSION_ID < 80100 ) so it only runs where it has an effect.

Testing Instructions

  1. On PHP 8.5 with WP_DEBUG and WP_DEBUG_LOG enabled, on WP < 7.0 (so the polyfill path runs), edit any post.
  2. Before this patch: deprecation notice referencing script-modules.php line 59 in the debug log.
  3. After this patch: no deprecation notice; script module translations continue to work (verify via the steps in I18N: Polyfill script module translations for WordPress < 7.0 #77214).

Testing Instructions for Keyboard

No UI changes — infrastructure-only.

Wraps the two ReflectionProperty/ReflectionMethod::setAccessible( true )
calls in lib/compat/wordpress-7.0/script-modules.php with a
PHP_VERSION_ID < 80100 guard so they no longer trigger the PHP 8.5
deprecation notice.

Follow-up to #77214. Fixes #78124.
@ramonjd ramonjd requested a review from spacedmonkey as a code owner May 11, 2026 01:41
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 11, 2026

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.

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

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: Presskopp <presskopp@git.wordpress.org>

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

@ramonjd ramonjd self-assigned this May 11, 2026
@ramonjd ramonjd added [Type] Plugin Interoperability Incompatibilities between a specific plugin and the block editor. Close with workaround notes. No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core labels May 11, 2026
@ramonjd ramonjd requested a review from manzoorwanijk May 11, 2026 01:42
Copy link
Copy Markdown
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

LGTM!

@ramonjd
Copy link
Copy Markdown
Member Author

ramonjd commented May 11, 2026

Thanks for the quick 👀 @t-hamano

@ramonjd ramonjd enabled auto-merge (squash) May 11, 2026 02:12
@ramonjd ramonjd merged commit 7145bd0 into trunk May 11, 2026
52 of 54 checks passed
@ramonjd ramonjd deleted the fix/reflection-setaccessible-php81 branch May 11, 2026 02:18
@github-actions github-actions Bot added this to the Gutenberg 23.2 milestone May 11, 2026
@paulopmt1 paulopmt1 added the [Type] Code Quality Issues or PRs that relate to code quality label May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Type] Code Quality Issues or PRs that relate to code quality [Type] Plugin Interoperability Incompatibilities between a specific plugin and the block editor. Close with workaround notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecated ReflectionMethod warning when editing a post (WP_DEBUG set to true) under PHP v8.5.1

3 participants