Remove usage of setAccessible() when core requires PHP 8.1

Created on 22 July 2021, over 3 years ago
Updated 20 July 2023, over 1 year ago

Problem/Motivation

Since PHP 8.1 setAccessible() method is no-op
https://github.com/php/php-src/blob/php-8.1.0beta1/UPGRADING#L486-L490
It's widely used in tests

Steps to reproduce

visit
- https://github.com/php/php-src/blob/php-8.1.0beta1/ext/reflection/php_re...
- https://github.com/php/php-src/blob/php-8.1.0beta1/ext/reflection/php_re...

Proposed resolution

Clean-up usage of the method when core require PHP 8.1

Remaining tasks

- agree and patch
- commit

User interface changes

no

API changes

no

Data model changes

no

Release notes snippet

Usage of ReflectionProperty::setAccessible() and ReflectionMethod::setAccessible() is removed

📌 Task
Status

Fixed

Version

11.0 🔥

Component
Base 

Last updated about 5 hours ago

Created by

🇫🇷France andypost

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • last update over 1 year ago
    Patch Failed to Apply
  • Status changed to Needs review over 1 year ago
  • last update over 1 year ago
    Patch Failed to Apply
  • 🇮🇳India karishmaamin

    Re-rolled patch against 11.x. Please review

  • Status changed to Needs work over 1 year ago
  • The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Status changed to Needs review over 1 year ago
  • last update over 1 year ago
    29,716 pass, 1 fail
  • 🇮🇳India mrinalini9 New Delhi

    Rerolled patch #35 for 11.x branch, please review it.

    Thanks & Regards,
    Mrinalini

  • Status changed to Needs work over 1 year ago
  • 🇳🇱Netherlands spokje

    If I search the codebase of 11.x-dev after applying the patch I still see 2 occurences of ->setAccessible(TRUE).

  • Status changed to Needs review over 1 year ago
  • last update over 1 year ago
    29,811 pass
  • 🇫🇷France andypost

    Fix broken test and remaining usage

  • Status changed to RTBC over 1 year ago
  • 🇺🇸United States smustgrave

    Applying patch and searching for setAccessible(TRUE) and got 0 results.
    Tests are green so seems like a non breaking change.

  • last update over 1 year ago
    29,815 pass
  • 🇺🇸United States xjm

    Adding credits for the aforementioned committer Slack discussions since those are easy to miss. (Didn't do full crediting.)

  • 🇬🇧United Kingdom catch

    The last 9.5.x bugfix came out last week (a month later than we might otherwise have done it, just because we skipped the previous month but still had some commits on the branch).

    So although we missed April for this one, it's actually ideal timing to do it now. Removing the date from the issue title both because it's passed, and I think this is fine to commit now we're down to security-only on 9.5 now, doesn't need to be a 10.2 beta target or anything.

  • last update over 1 year ago
    29,815 pass
    • longwave committed 9884cfbd on 10.1.x
      Issue #3224941 by andypost, Akram Khan, ravi.shankar, SandeepSingh199,...
    • longwave committed 69333763 on 11.x
      Issue #3224941 by andypost, Akram Khan, ravi.shankar, SandeepSingh199,...
  • Status changed to Fixed over 1 year ago
  • 🇬🇧United Kingdom longwave UK

    Committed and pushed 69333763c3 to 11.x (10.2.x) and 9884cfbd90 to 10.1.x. Thanks!

  • 🇫🇷France andypost

    Thank you! 0 additions and 30 deletions

  • 🇮🇳India ShariRoluthon

    Check the PHP 8.1 Release Notes: Before making any changes, review the official PHP 8.1 release notes and documentation to understand the reasons behind the deprecation or removal of setAccessible() and any recommended alternatives.

    Find Affected Code: Identify all occurrences of setAccessible() in your codebase. This can be done through simple text searches or using static analysis tools, depending on the size of your project.

    Remove Direct Usage: If the functionality provided by setAccessible() is no longer supported or safe to use, you will need to find alternative approaches to achieve the same functionality without using it. Consider alternatives provided by the language or specific libraries.

    Use Reflection Correctly: If you were using setAccessible() to access private or protected properties or methods in tests, consider using the Reflection API to access those elements instead. With Reflection, you can change the accessibility of properties and methods for testing purposes without relying on setAccessible(). This approach allows for better control and reduces potential security risks.

    Update Third-Party Libraries: If you are using third-party libraries that rely on setAccessible(), check for updates or look for alternative libraries that are compatible with PHP 8.1 and beyond.

    Test Thoroughly: After making the necessary changes, thoroughly test your code to ensure that the removal of setAccessible() does not introduce any regressions or issues in your application.

    Update Minimum PHP Version: Update your project's minimum required PHP version to PHP 8.1 to prevent accidental usage of deprecated or removed functions in lower versions.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024