Skip to content

Removes three calls to ReflectionProperty::setAccessible() / ReflectionMethod::setAccessible() in the test suite above PHP 8.1 - #942

Merged
masteradhoc merged 4 commits into
WordPress:masterfrom
masteradhoc:remove-setAccessible
Jul 31, 2026
Merged

Removes three calls to ReflectionProperty::setAccessible() / ReflectionMethod::setAccessible() in the test suite above PHP 8.1#942
masteradhoc merged 4 commits into
WordPress:masterfrom
masteradhoc:remove-setAccessible

Conversation

@masteradhoc

@masteradhoc masteradhoc commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

What?

Removes three calls to ReflectionProperty::setAccessible() / ReflectionMethod::setAccessible() for PHP 8.1+ in the test suite.

Fixes #

Why?

See: https://www.php.net/manual/de/reflectionmethod.setaccessible.php

Since PHP 8.1, reflection properties and methods are accessible without calling setAccessible( true ), making the call a no-op. As of PHP 8.5, calling it is deprecated and emits a PHP Deprecated notice, which was showing up as noise in test runs (tests/class-two-factor-core.php:168, :2374, tests/providers/class-two-factor-totp.php:457).

............................................................... 63 / 232 ( 27%) [23-Jul-2026 20:30:55 UTC] PHP Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /var/www/html/wp-content/plugins/two-factor/tests/class-two-factor-core.php on line 168 .......Received a non-notice error: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /var/www/html/wp-content/plugins/two-factor/tests/class-two-factor-core.php on line 168 [23-Jul-2026 20:30:55 UTC] PHP Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /var/www/html/wp-content/plugins/two-factor/tests/class-two-factor-core.php on line 2398 Received a non-notice error: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1Received a non-notice error: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1.Received a non-notice error: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1Received a non-notice error: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1Received a non-notice error: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1...Received a non-notice error: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /var/www/html/wp-content/plugins/two-factor/tests/class-two-factor-core.php on line 2398 ...................................F................ 126 / 232 ( 54%) ............................................................... 189 / 232 ( 81%) [23-Jul-2026 20:30:57 UTC] PHP Deprecated: Method ReflectionMethod::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /var/www/html/wp-content/plugins/two-factor/tests/providers/class-two-factor-totp.php on line 457 ...................................... Deprecated: Method ReflectionMethod::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /var/www/html/wp-content/plugins/two-factor/tests/providers/class-two-factor-totp.php on line 457

How?

Deleted the three now-redundant setAccessible( true ) lines. No behavior change — the reflection objects were already accessible without it.

Use of AI Tools

Testing Instructions

  1. Run the plugin's PHPUnit suite on PHP 8.5.
  2. Confirm the ReflectionProperty::setAccessible() is deprecated / ReflectionMethod::setAccessible() is deprecated notices no longer appear.

Changelog Entry

Fixed - Removed deprecated setAccessible() calls in the test suite to prevent PHP 8.5 deprecation notices.

Open WordPress Playground Preview

@masteradhoc masteradhoc changed the title Removes three calls to ReflectionProperty::setAccessible() / ReflectionMethod::setAccessible() in the test suite Removes three calls to ReflectionProperty::setAccessible() / ReflectionMethod::setAccessible() in the test suite above PHP 8.1 Jul 26, 2026
@masteradhoc
masteradhoc marked this pull request as ready for review July 26, 2026 12:31
@github-actions

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.

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: masteradhoc <masteradhoc@git.wordpress.org>

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates the PHPUnit test suite to avoid PHP 8.5 deprecation notices from ReflectionProperty::setAccessible() / ReflectionMethod::setAccessible() by only calling setAccessible( true ) on PHP versions where it still has an effect (pre-8.1). This keeps the tests compatible with older PHP versions while removing the deprecation noise on newer versions.

Changes:

  • Wrapped ReflectionProperty::setAccessible( true ) calls in PHP version guards in Two_Factor_Core tests.
  • Wrapped ReflectionMethod::setAccessible( true ) call in a PHP version guard in the TOTP provider tests.
  • Ensures PHP 8.5+ test runs no longer emit setAccessible() deprecation notices.

Reviewed changes

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

File Description
tests/providers/class-two-factor-totp.php Guard ReflectionMethod::setAccessible( true ) for PHP < 8.1 in the reflection helper to avoid PHP 8.5 deprecations.
tests/class-two-factor-core.php Guard ReflectionProperty::setAccessible( true ) for PHP < 8.1 in two reflection-based test helpers/paths to avoid PHP 8.5 deprecations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@masteradhoc masteradhoc added this to the 0.17.0 milestone Jul 28, 2026
@masteradhoc masteradhoc self-assigned this Jul 29, 2026
@masteradhoc
masteradhoc merged commit 54ec54d into WordPress:master Jul 31, 2026
29 checks passed
@masteradhoc
masteradhoc deleted the remove-setAccessible branch July 31, 2026 21:07
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.

3 participants