diff --git a/backup/util/settings/tests/settings_test.php b/backup/util/settings/tests/settings_test.php index a50023c03d1..45bc4ecd811 100644 --- a/backup/util/settings/tests/settings_test.php +++ b/backup/util/settings/tests/settings_test.php @@ -127,7 +127,8 @@ class backp_settings_testcase extends basic_testcase { $this->assertTrue($e instanceof base_setting_exception); $this->assertEquals($e->errorcode, 'incorrect_object_passed'); } catch (TypeError $e) { - // PHP7 will catch type errors for us. + // On PHP7+ we get a TypeError raised, lets check we've the right error. + $this->assertRegexp('/must be an instance of backup_setting_ui/', $e->getMessage()); } restore_error_handler(); @@ -143,7 +144,8 @@ class backp_settings_testcase extends basic_testcase { $this->assertTrue($e instanceof base_setting_exception); $this->assertEquals($e->errorcode, 'incorrect_object_passed'); } catch (TypeError $e) { - // PHP7 will catch type errors for us. + // On PHP7+ we get a TypeError raised, lets check we've the right error. + $this->assertRegexp('/must be an instance of backup_setting_ui/', $e->getMessage()); } restore_error_handler(); @@ -307,7 +309,8 @@ class backp_settings_testcase extends basic_testcase { $this->assertTrue($e instanceof backup_setting_exception); $this->assertEquals($e->errorcode, 'incorrect_object_passed'); } catch (TypeError $e) { - // PHP7 will catch type errors for us. + // On PHP7+ we get a TypeError raised, lets check we've the right error. + $this->assertRegexp('/must be an instance of base_setting/', $e->getMessage()); } restore_error_handler(); diff --git a/lib/classes/shutdown_manager.php b/lib/classes/shutdown_manager.php index 8b01ba0d759..2a11ae2d090 100644 --- a/lib/classes/shutdown_manager.php +++ b/lib/classes/shutdown_manager.php @@ -81,6 +81,9 @@ class core_shutdown_manager { } } catch (Exception $e) { error_log('Exception ignored in shutdown function '.var_export($callback, true).':'.$e->getMessage()); + } catch (Throwable $e) { + // Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5). + error_log('Exception ignored in shutdown function '.var_export($callback, true).':'.$e->getMessage()); } } diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index 78b11df710b..4540c7e1962 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -2431,7 +2431,7 @@ abstract class moodle_database { * automatically if exceptions not caught. * * @param moodle_transaction $transaction An instance of a moodle_transaction. - * @param $e The related exception/throwable to this transaction rollback. + * @param Exception|Throwable $e The related exception/throwable to this transaction rollback. * @return void This does not return, instead the exception passed in will be rethrown. */ public function rollback_delegated_transaction(moodle_transaction $transaction, $e) { diff --git a/lib/dml/moodle_transaction.php b/lib/dml/moodle_transaction.php index a9484419c73..839f98d5cd3 100644 --- a/lib/dml/moodle_transaction.php +++ b/lib/dml/moodle_transaction.php @@ -95,7 +95,7 @@ class moodle_transaction { /** * Rollback all current delegated transactions. * - * @param $e mandatory exception/throwable + * @param Exception|Throwable $e mandatory exception/throwable * @return void */ public function rollback($e) { diff --git a/lib/phpunit/classes/advanced_testcase.php b/lib/phpunit/classes/advanced_testcase.php index 410cc05ca5b..d09d5cdf357 100644 --- a/lib/phpunit/classes/advanced_testcase.php +++ b/lib/phpunit/classes/advanced_testcase.php @@ -91,7 +91,8 @@ abstract class advanced_testcase extends base_testcase { } catch (Exception $ex) { $e = $ex; } catch (Throwable $ex) { - $e = $ex; // PHP7. + // Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5). + $e = $ex; } if (isset($e)) { diff --git a/lib/phpunit/classes/basic_testcase.php b/lib/phpunit/classes/basic_testcase.php index 84f8506630e..ba7d000bf01 100644 --- a/lib/phpunit/classes/basic_testcase.php +++ b/lib/phpunit/classes/basic_testcase.php @@ -66,7 +66,8 @@ abstract class basic_testcase extends base_testcase { } catch (Exception $ex) { $e = $ex; } catch (Throwable $ex) { - $e = $ex; // PHP7. + // Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5). + $e = $ex; } if (isset($e)) { diff --git a/lib/phpunit/classes/database_driver_testcase.php b/lib/phpunit/classes/database_driver_testcase.php index 14293b26657..5236a6e88fc 100644 --- a/lib/phpunit/classes/database_driver_testcase.php +++ b/lib/phpunit/classes/database_driver_testcase.php @@ -145,7 +145,8 @@ abstract class database_driver_testcase extends base_testcase { } catch (Exception $ex) { $e = $ex; } catch (Throwable $ex) { - $e = $ex; // PHP7. + // Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5). + $e = $ex; } if (isset($e)) { diff --git a/lib/setuplib.php b/lib/setuplib.php index ce4dc325474..ee6b8ee61aa 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -381,7 +381,8 @@ function default_exception_handler($ex) { } catch (Exception $e) { $out_ex = $e; } catch (Throwable $e) { - $out_ex = $e; // PHP7. + // Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5). + $out_ex = $e; } if (isset($out_ex)) { diff --git a/lib/upgradelib.php b/lib/upgradelib.php index 7832ce18123..c44cee9bd6f 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -1547,6 +1547,9 @@ function install_core($version, $verbose) { cache_helper::purge_all(); } catch (exception $ex) { upgrade_handle_exception($ex); + } catch (Throwable $ex) { + // Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5). + upgrade_handle_exception($ex); } } @@ -1617,6 +1620,9 @@ function upgrade_core($version, $verbose) { print_upgrade_part_end('moodle', false, $verbose); } catch (Exception $ex) { upgrade_handle_exception($ex); + } catch (Throwable $ex) { + // Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5). + upgrade_handle_exception($ex); } } @@ -1651,6 +1657,9 @@ function upgrade_noncore($verbose) { } catch (Exception $ex) { upgrade_handle_exception($ex); + } catch (Throwable $ex) { + // Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5). + upgrade_handle_exception($ex); } }