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

PHP8 string is less than 0 - problem with backup infrastructure

    XMLWordPrintable

Details

    Description

      After updating to PHP8.0 we encountered a strange error when running unit tests, for example completionlib_test::test_course_delete_prerequisite.

      The error was backup_processor_exception: error/processorvariablenotfound, below I provide the call stack for completeness but this does not happen in a vanilla Moodle.

      I chased the problem down to the following issue, caused by the different behaviour of checking that a string is less than zero in PHP8:

      We have a local plugin which implements the backup API. In local/myplugin/backup/moodle2/backup_local_myplugin_plugin.class.php we define a function define_course_plugin_structure() which calls backup_nested_element(...)->set_source_sql($sql, $params) where $params have values that are paths.

      The function convert_params_to_values in backup/utils/dbops/backup_structure_dbops.class.php in line 75 contains the following check:

      } else if ($param < 0) { // Possibly one processor variable, let's process it
      

      In our case, when $param is instantiated with the string representing a path like "/1/3/148000/", this comparison returns true and the code tries to read the value from the processor object resulting in the error.

      I would propose to change the above check to:

      } else if (is_numeric($param) && $param < 0) { // Possibly one processor variable, let's process it
      

      which fixes the problem for us, seems to be safer for any other third party plugin and still appears to do the job it is supposed to do.

      The steps to reproduce are a bit complicated as they imply writing a plugin implementing the backup API with similar features to the ones described above.

      Attachments

        Activity

          People

            ManeggiaP Paola Maneggia
            ManeggiaP Paola Maneggia
            Andrew Lyons Andrew Lyons
            Huong Nguyen Huong Nguyen
            CiBoT CiBoT
            Votes:
            4 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              9/Oct/23

              Time Tracking

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