Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-75952

Remove all Reflection setAccessible() uses from core once php81 is the minimum

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • 4.4
    • 4.1
    • General, Unit tests
    • MOODLE_401_STABLE
    • MOODLE_404_STABLE
    • Hide

      Sanity check

      1. Run grep -ri setAccessible *
      2. Verify that the 5 matches correspond to 3rd-part libraries. They have not been modified on purpose. Ignore any match happening within the /vendor directory, if you have composer stuff installed.

      CI

      1. Verify that everything (GHA, ToBiC, CiBoT, ...) continues passing ok. It should.
      Show
      Sanity check Run grep -ri setAccessible * Verify that the 5 matches correspond to 3rd-part libraries. They have not been modified on purpose. Ignore any match happening within the /vendor directory, if you have composer stuff installed. CI Verify that everything (GHA, ToBiC, CiBoT, ...) continues passing ok. It should.

      Starting with PHP 8.1, the setAccessible() methods in Reflection classes are not needed any more because all properties and methods are accesible by default.

      ReflectionProperty::setAccessible() and ReflectionMethod::setAccessible()
      no longer have an effect. Properties and methods are always considered
      accessible through reflection.
      RFC: https://wiki.php.net/rfc/make-reflection-setaccessible-no-op

      In PHP 8.1 (and hopefully some more versions, still don't know if PHP 8.2 changes this), those setAccessible() are simply ignored, without emitting any notice/warning/deprecation.

      Once PHP 8.1 is the minimum required for Moodle (say for example Moodle 4.5, though that could be wrong, has not been decided yet) we'll be able to safely remove all uses from core.

      Note that this may need another solution if suddenly, for example in PHP 8.2/8.3 they decide the methods to start emitting notice/warning/deprecation.

      Ciao

        1. MDL-75952_test1.png
          57 kB
          Sara Arjona (@sarjona)

            stronk7 Eloy Lafuente (stronk7)
            stronk7 Eloy Lafuente (stronk7)
            Jun Pataleta Jun Pataleta
            Andrew Lyons Andrew Lyons
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 hours, 18 minutes
                2h 18m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.