throw new moodle_exception('redirecterrordetected', 'error');
}
+ // prevent debug errors - make sure context is properly initialised
+ $PAGE->set_context(null);
+
if ($url instanceof moodle_url) {
$url = $url->out(false);
}
$url = $SESSION->sid_process_url($url);
}
- if (function_exists('error_get_last')) {
- $lasterror = error_get_last();
- //NOTE: problem here is that this contains error even if error hidden with @do();
- }
- $debugdisableredirect = defined('DEBUGGING_PRINTED') ||
- (!empty($CFG->debugdisplay) && !empty($lasterror) && ($lasterror['type'] & DEBUG_DEVELOPER));
+ $debugdisableredirect = false;
+ do {
+ if (defined('DEBUGGING_PRINTED')) {
+ // some debugging already printed, no need to look more
+ $debugdisableredirect = true;
+ break;
+ }
+
+ if (empty($CFG->debugdisplay) or empty($CFG->debug)) {
+ // no errors should be displayed
+ break;
+ }
+
+ if (!function_exists('error_get_last') or !$lasterror = error_get_last()) {
+ break;
+ }
+
+ if (!($lasterror['type'] & $CFG->debug)) {
+ //last error not interesting
+ break;
+ }
+
+ // watch out here, @hidden() errors are returned from error_get_last() too
+ if (headers_sent()) {
+ //we already started printing something - that means errors likely printed
+ $debugdisableredirect = true;
+ break;
+ }
+
+ if (ob_get_level() and ob_get_contents()) {
+ // there is something waiting to be printed, hopefully it is the errors,
+ // but it might be some error hidden by @ too - such as the timezone mess from setup.php
+ $debugdisableredirect = true;
+ break;
+ }
+ } while (false);
if (!empty($message)) {
if ($delay === -1 || !is_numeric($delay)) {