From b388c7664db1d4e5cc5bce89e7267dac38dd2091 Mon Sep 17 00:00:00 2001
From: tjhunt
Date: Sun, 1 Apr 2007 22:19:39 +0000
Subject: [PATCH] Another attempt to get redirect() to not redirect if an error
was output to the screen, to make dubuggin easier. Sorry I had not noticed
the bit in the docs that says error_get_last was PHP 5.2.0+.
---
lib/weblib.php | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/lib/weblib.php b/lib/weblib.php
index d88dec5258d..45d7d2ecb19 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -4977,6 +4977,19 @@ function notice_yesno ($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno
print_box_end();
}
+/**
+ * Provide an definition of error_get_last for PHP before 5.2.0. This simply
+ * returns NULL, since there is not way to get the right answer.
+ */
+if (!version_compare(phpversion(), '5.2.0') >= 0) {
+ // the eval is needed to prevent PHP 5.2+ from getting a parse error!
+ eval('
+ function error_get_last() {
+ return NULL;
+ }
+ ');
+}
+
/**
* Redirects the user to another page, after printing a notice
*
@@ -5008,9 +5021,10 @@ function redirect($url, $message='', $delay=-1, $adminroot = '') {
$surl = addslashes($url);
/// At developer debug level. Don't redirect if errors have been printed on screen.
- $errorprinted = false;
- if (debugging('', DEBUG_DEVELOPER) && $CFG->debugdisplay && false /* && error_get_last()*/) {
- $errorprinted = true;
+/// Currenly only works in PHP 5.2+
+ $error = error_get_last();
+ $errorprinted = debugging('', DEBUG_DEVELOPER) && $CFG->debugdisplay && !empty($error);
+ if ($errorprinted) {
$message = "Error output, so disabling automatic redirect.
" . $message;
}