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

PHP 8.2: Dynamic Properties are deprecated

    XMLWordPrintable

Details

    • MOODLE_402_STABLE
    • Hide

      Test are covered by PHP Unit and Behat

      Show
      Test are covered by PHP Unit and Behat
    • 6
    • Team Hedgehog Sprint 1 review, Team Hedgehog Sprint 2.1, Team Hedgehog Sprint 2.2, Team Hedgehog 2023 Sprint 1.3, Team Hedgehog 2023 Sprint 1.4, Team Hedgehog 2023 Sprint 2.0, Team Hedgehog 2023 Sprint 2.1, Team Hedgehog 2023 Sprint 2.2

    Description

      From PHP 8.2, if someone tries to set a value for a class property which does not have a definitino, a deprecation notice will be emitted. For example:

      class User {
          private int $uid;
      }
       
      $user = new User();
      $user->name = 'Foo';
      

      Deprecated: Creation of dynamic property User::$name is deprecated in ... on line ...
      

      Also from internally:

      class User {
          public function __construct() {
              $this->name = 'test';
          }
      }
       
      new User();
      

      Deprecated: Creation of dynamic property User::$name is deprecated in ... on line ...
      

      Much more detail here: https://php.watch/versions/8.2/dynamic-properties-deprecated

      We should look at writing a sniff for this if possible.

      Note: For some legacy code, we may choose to work around this using the AllowDynamicProperties attribute:

       #[AllowDynamicProperties]
       class User {
           private int $uid;
       }
       
       $user = new User();
       $user->name = 'Foo';
      

      https://php.watch/versions/8.2/dynamic-properties-deprecated#AllowDynamicProperties

      Other cases not affected

      • stdClass
      • classes with a magic __get and __set method

      phpstan configuration

      I used the following phpstan configuration to genreate the above:

      parameters
        # Dynamic properties emits warnings from PHP 8.2 onwards.
        checkDynamicProperties: true
      

      Note: I would recommend generating a baseline first, then adding the above configuration, and then running again against the baseline with the new configuration. This will identify any problem areas.

      Attachments

        Issue Links

          1.
          PHP 8.2: Dynamic Properties are deprecated for question_display_options::$statewhichincorrect Sub-task Closed Tim Hunt
          2.
          PHP 8.2: Dynamic Properties are deprecated for analytics Sub-task Closed Meirza
          3.
          PHP 8.2: Dynamic Properties are deprecated for files, mod BBB, chat, survey and feedback Sub-task Closed Meirza
          4.
          PHP 8.2: Dynamic Properties are deprecated for mod_forum Sub-task Closed Meirza
          5.
          PHP 8.2: Dynamic Properties are deprecated for backup Sub-task Closed Meirza
          6.
          PHP 8.2: Dynamic Properties are deprecated for mod_wiki Sub-task Closed Meirza
          7.
          PHP 8.2: Dynamic Properties are deprecated for mod_assign Sub-task Closed Meirza
          8.
          PHP 8.2: Dynamic Properties are deprecated for mnet Sub-task Closed Meirza
          9.
          PHP 8.2: Dynamic Properties are deprecated for others Sub-task Closed Meirza
          10.
          PHP 8.2: Dynamic Properties are deprecated for admin Sub-task Closed Meirza
          11.
          PHP 8.2: Dynamic Properties are deprecated for mod data, glossary, lesson, lti and scorm Sub-task Closed Meirza
          12.
          PHP 8.2: Dynamic Properties are deprecated for repository Sub-task Closed Meirza
          13.
          PHP 8.2: Dynamic Properties are deprecated for lib (exclude 3rd party) Sub-task Closed Meirza
          14.
          PHP 8.2: Dynamic Properties are deprecated for questionbase.php Sub-task Closed Shamim Rezaie
          15.
          PHP 8.2: Dynamic Properties are deprecated for grade Sub-task Closed Meirza
          16.
          PHP 8.2: Dynamic Properties are deprecated for mod_workshop Sub-task Closed Meirza
          17.
          PHP 8.2: Dynamic Properties are deprecated for the third-party lib Sub-task Closed Meirza
          18.
          PHP 8.2: Dynamic Properties are deprecated for quiz and question Sub-task Closed Meirza
          19.
          PHP 8.2: Dynamic Properties are deprecated for the Google lib Sub-task Closed Meirza
          20.
          PHP 8.2: Dynamic Properties are deprecated for lib tests Sub-task Closed Meirza
          21.
          PHP 8.2: Dynamic Properties are deprecated for lib portfolio Sub-task Closed Meirza
          22.
          PHP 8.2: Dynamic Properties are deprecated for lib classes Sub-task Closed Meirza
          23.
          PHP 8.2: Dynamic Properties are deprecated for lib grade Sub-task Closed Meirza
          24.
          PHP 8.2: Dynamic Properties are deprecated for lib form Sub-task Closed Meirza
          25.
          PHP 8.2: Dynamic Properties are deprecated for lib filestorage Sub-task Closed Meirza
          26.
          PHP 8.2: Dynamic Properties are deprecated for lib editor Sub-task Closed Meirza
          27.
          PHP 8.2: Dynamic Properties are deprecated for lib dml Sub-task Closed Meirza
          28.
          PHP 8.2: Dynamic Properties are deprecated for core libraries Sub-task Closed Meirza
          29.
          PHP 8.2: Dynamic Properties are deprecated for ADOdb for Moodle 4.2 Sub-task Closed Meirza
          30.
          PHP 8.2: Dynamic Properties are deprecated for Bennu Sub-task Closed Meirza
          31.
          PHP 8.2: Dynamic Properties are deprecated for htmlpurifier Sub-task Closed Meirza
          32.
          PHP 8.2: Dynamic Properties are deprecated for legacy LTI Provider library Sub-task Closed Meirza
          33.
          PHP 8.2: Dynamic Properties are deprecated for PEAR Sub-task Closed Meirza
          34.
          PHP 8.2: Dynamic Properties are deprecated for PHPMailer Sub-task Closed Meirza
          35.
          PHP 8.2: Dynamic Properties are deprecated for H5P Sub-task Closed Meirza
          36.
          PHP 8.2: Dynamic Properties are deprecated for mod_assign (round 2) Sub-task Closed Andrew Lyons
          37.
          Redo PHP 8.2 fix for cache_config dynamic property Sub-task Closed Jonathan Champ

          Activity

            People

              meirza.arson@moodle.com Meirza
              dobedobedoh Andrew Lyons
              Raquel Ortega Raquel Ortega
              Votes:
              3 Vote for this issue
              Watchers:
              16 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 2 days, 40 minutes Original Estimate - 2 days, 40 minutes
                  2d 40m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 10 weeks, 3 hours, 16 minutes
                  10w 3h 16m

                  Clockify

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