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

Persistent class uses static cache incorrectly, breaks under PHP8.1

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.11.5
    • 3.11.4, 4.0
    • Other

      Class core\persistent has a function

      final public static function properties_definition() {
          static $def = null;
      

      that uses static variable for caching the properties definitions that is supposed to be cached for the current class. It works in PHP7 and PHP8.0, but it breaks in PHP8.1 and I personally find the new behavior more logical.

        . When a method using static variables is inherited (but not overridden), the
          inherited method will now share static variables with the parent method.
       
              class A {
                  public static function counter() {
                      static $counter = 0;
                      $counter++;
                      return $counter;
                  }
              }
              class B extends A {}
       
              var_dump(A::counter()); // int(1)
              var_dump(A::counter()); // int(2)
              var_dump(B::counter()); // int(3), previously int(1)
              var_dump(B::counter()); // int(4), previously int(2)
       
          This means that static variables in methods now behave the same way as
          static properties.
      

      RFC https://wiki.php.net/rfc/static_variable_inheritance

            marina Marina Glancy
            marina Marina Glancy
            Paul Holden Paul Holden
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            CiBoT CiBoT
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

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

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