MDL-52284 core: PHP7 engine errors have type Throwable

This commit is contained in:
Marina Glancy 2015-12-09 11:55:58 +08:00
parent d74b7e424f
commit 1766e6a17f
9 changed files with 28 additions and 9 deletions

View File

@ -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();

View File

@ -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());
}
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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)) {

View File

@ -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)) {

View File

@ -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)) {

View File

@ -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)) {

View File

@ -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);
}
}