Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-76411 PHP 8.2: Dynamic Properties are deprecated
  3. MDL-77340

PHP 8.2: Dynamic Properties are deprecated for lib (exclude 3rd party)

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Duplicate
    • Icon: Critical Critical
    • None
    • 4.2
    • Libraries
    • MOODLE_402_STABLE
    • MDL-77340-master
    • Hide
      Prerequisite:

      The scanning process will consume memory resources. I suggest increasing the memory limit in your PHP.ini to 256M, or more if needed.

      Install PHPStan

      composer require --dev phpstan/phpstan
      

      Because PHPStan could not read properties in the parent class if the parent is an abstract class, I separated the analysis per folder to explain it easily.

      1/ Lib_core (core lib)

      Download : phpstan_mdl77340_lib.neon and put the file into Moodle's root folder.

      1. Run the analysis:

        php -dmemory_limit=256M vendor/bin/phpstan analyse --configuration phpstan_mdl77341_lib.neon -vvv | tee result.txt 

      2. Search for "Access to an undefined property".

        grep -i "Access to an undefined property" result.txt  

      3. Verify that you will have the below results:

        172    Access to an undefined property pdf::$l.                                              
        201    Access to an undefined property pdf::$CoreFonts.                                      
        211    Access to an undefined property pdf::$fontlist.                                       
        378    Access to an undefined property moodle_url::$fragment. 

      • PDF: All three properties have been defined in the parent class.
      • Moodle_url: The fragment key will not exist because moodle_url strips the fragment before assigning properties.

      2/ Lib_dml

      1. Download : phpstan_mdl77340_dml.neon and put the file into Moodle's root folder.
      2. Repeat processes 1 and 2 at the Lib_core but use the above file.
      3. Verify that you will have the below results:

        205    Access to an undefined property core\dml_table_test::$tdb.                            
        51     Access to an undefined property core\dml_test::$tdb.  

        The $tdb property has been defined in the parent class, database_driver_testcase.

      3/ Lib_editor

      1. Download : phpstan_mdl77340_editor.neon and put the file into Moodle's root folder.
      2. Repeat processes 1 and 2 at the Lib_core but use the above file.
      3. Verify that you will have a bunch of undefined property errors. That was a false alarm because all properties have been defined in the parent class. For example:

        editor_atto_subplugins_setting::$nosave
        

        The $nosave has been defined in the parent class abstract class admin_setting.

      4/ Lib_filestorage

      1. Download : phpstan_mdl77340_filestorage.neon and put the file into Moodle's root folder.
      2. Repeat processes 1 and 2 at the Lib_core but use the above file.
      3. Verify that you will have an empty results.

      5/ Lib_form

      1. Download : phpstan_mdl77340_form.neon and put the file into Moodle's root folder.
      2. Repeat processes 1 and 2 at the Lib_core but use the above file.
      3. Verify that you will have a bunch of undefined property errors. That was a false alarm because all properties have been defined in the parent class. For example:

        MoodleQuickForm_text::$_flagFrozen
        

        The $_flagFrozen has been defined in the parent class HTML_QuickForm_element.

      6/ Lib_grade

      1. Download : phpstan_mdl77340_grade.neon and put the file into Moodle's root folder.
      2. Repeat processes 1 and 2 at the Lib_core but use the above file.
      3. Verify that you will have an empty results.

      7/ Lib_classes

      1. Download : phpstan_mdl77340_classes.neon and put the file into Moodle's root folder.
      2. Repeat processes 1 and 2 at the Lib_core but use the above file.
      3. Verify that you will have a bunch of undefined property errors. That was a false alarm because all properties have been defined in the parent class. For example:

        core\analytics\time_splitting\single_range::$analysable
        

        The $analysable has been defined in the parent abstract class base.

      8/ Lib_portfolio

      1. Download : phpstan_mdl77340_portfolio.neon and put the file into Moodle's root folder.
      2. Repeat processes 1 and 2 at the Lib_core but use the above file.
      3. Verify that you will have a bunch of undefined property errors. That was a false alarm because all properties have been defined in the parent class. For example:

        portfolio_export_form::$_customdata
        

        The $_customdata has been defined in the parent abstract class moodleform

      9/ Lib_tests

      1. Download : phpstan_mdl77340_tests.neon and put the file into Moodle's root folder.
      2. Repeat processes 1 and 2 at the Lib_core but use the above file.
      3. Verify that you will have a bunch of undefined property errors. That was a false alarm because all properties have been defined in the parent class. For example:

        core\core_testable_exporter::$related
        

        The $related has been defined in the parent abstract class exporter

      Show
      Prerequisite: The scanning process will consume memory resources. I suggest increasing the memory limit in your PHP.ini to 256M, or more if needed. Install PHPStan composer require --dev phpstan/phpstan Because PHPStan could not read properties in the parent class if the parent is an abstract class, I separated the analysis per folder to explain it easily. 1/ Lib_core (core lib) Download : phpstan_mdl77340_lib.neon and put the file into Moodle's root folder. Run the analysis: php -dmemory_limit=256M vendor/bin/phpstan analyse --configuration phpstan_mdl77341_lib.neon -vvv | tee result.txt Search for "Access to an undefined property". grep -i "Access to an undefined property" result.txt  Verify that you will have the below results: 172    Access to an undefined property pdf::$l.                                               201    Access to an undefined property pdf::$CoreFonts.                                     211    Access to an undefined property pdf::$fontlist.                                       378    Access to an undefined property moodle_url::$fragment. PDF: All three properties have been defined in the parent class. Moodle_url: The fragment key will not exist because moodle_url strips the fragment before assigning properties. 2/ Lib_dml Download : phpstan_mdl77340_dml.neon and put the file into Moodle's root folder. Repeat processes 1 and 2 at the Lib_core but use the above file. Verify that you will have the below results: 205    Access to an undefined property core\dml_table_test::$tdb.                             51     Access to an undefined property core\dml_test::$tdb. The $tdb property has been defined in the parent class, database_driver_testcase. 3/ Lib_editor Download : phpstan_mdl77340_editor.neon and put the file into Moodle's root folder. Repeat processes 1 and 2 at the Lib_core but use the above file. Verify that you will have a bunch of undefined property errors. That was a false alarm because all properties have been defined in the parent class. For example: editor_atto_subplugins_setting::$nosave The $nosave has been defined in the parent class abstract class admin_setting. 4/ Lib_filestorage Download : phpstan_mdl77340_filestorage.neon and put the file into Moodle's root folder. Repeat processes 1 and 2 at the Lib_core but use the above file. Verify that you will have an empty results. 5/ Lib_form Download : phpstan_mdl77340_form.neon and put the file into Moodle's root folder. Repeat processes 1 and 2 at the Lib_core but use the above file. Verify that you will have a bunch of undefined property errors. That was a false alarm because all properties have been defined in the parent class. For example: MoodleQuickForm_text::$_flagFrozen The $_flagFrozen has been defined in the parent class HTML_QuickForm_element. 6/ Lib_grade Download : phpstan_mdl77340_grade.neon and put the file into Moodle's root folder. Repeat processes 1 and 2 at the Lib_core but use the above file. Verify that you will have an empty results. 7/ Lib_classes Download : phpstan_mdl77340_classes.neon and put the file into Moodle's root folder. Repeat processes 1 and 2 at the Lib_core but use the above file. Verify that you will have a bunch of undefined property errors. That was a false alarm because all properties have been defined in the parent class. For example: core\analytics\time_splitting\single_range::$analysable The $analysable has been defined in the parent abstract class base. 8/ Lib_portfolio Download : phpstan_mdl77340_portfolio.neon and put the file into Moodle's root folder. Repeat processes 1 and 2 at the Lib_core but use the above file. Verify that you will have a bunch of undefined property errors. That was a false alarm because all properties have been defined in the parent class. For example: portfolio_export_form::$_customdata The $_customdata has been defined in the parent abstract class moodleform 9/ Lib_tests Download : phpstan_mdl77340_tests.neon and put the file into Moodle's root folder. Repeat processes 1 and 2 at the Lib_core but use the above file. Verify that you will have a bunch of undefined property errors. That was a false alarm because all properties have been defined in the parent class. For example: core\core_testable_exporter::$related The $related has been defined in the parent abstract class exporter
    • 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

      This issue was created to fix all the PHP files inside the lib/ folder but excluding the third-party libraries related to dynamic properties deprecation on PHP 8.2.

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

      >>> For the third-party libraries please check MDL-77133. <<<

            meirza.arson@moodle.com Meirza
            meirza.arson@moodle.com Meirza
            Safat Shahin Safat Shahin
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 2 hours Original Estimate - 2 hours
                2h
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 days, 6 hours, 37 minutes
                3d 6h 37m

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