Details
-
Bug
-
Resolution: Fixed
-
Minor
-
3.11.10, 4.0.4
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.