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

CLONE - PHP 8.2: Dynamic Properties are deprecated

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Critical Critical
    • None
    • 4.2
    • General
    • None
    • MOODLE_402_STABLE

      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

            Unassigned Unassigned
            dobedobedoh Andrew Lyons
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

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