Commit 8d17e071 authored by Aaron Wells's avatar Aaron Wells
Browse files

Silence most E_STRICT errors

Bug 1268746: In PHP 5.4 E_ALL changed to include E_STRICT, causing Mahara to throw
a lot of strict standards errors. This should silence most of them.

HOWEVER, because most strict standards happen at compile-time, this will have no
effect on strict standards errors caused in the files that have already been
loaded by the time we call error_reporting() and set_error_handler(), which includes:
 - The file invoked directly by the URL
 - init.php
 - errors.php
 - config.php
 - config-defaults.php

Change-Id: I7a7fdf7facb1f30e186a0e8a27f1c3b7473200da
parent 2d0a6ccd
...@@ -91,6 +91,12 @@ if (empty($CFG->directorypermissions)) { ...@@ -91,6 +91,12 @@ if (empty($CFG->directorypermissions)) {
} }
$CFG->filepermissions = $CFG->directorypermissions & 0666; $CFG->filepermissions = $CFG->directorypermissions & 0666;
// Now that we've loaded the configs, we can override the default error settings
// from errors.php
$errorlevel = $CFG->error_reporting;
error_reporting($errorlevel);
set_error_handler('error', $errorlevel);
// core libraries // core libraries
require('mahara.php'); require('mahara.php');
ensure_sanity(); ensure_sanity();
......
...@@ -110,6 +110,17 @@ $cfg->log_environ_targets = LOG_TARGET_SCREEN | LOG_TARGET_ERRORLOG; ...@@ -110,6 +110,17 @@ $cfg->log_environ_targets = LOG_TARGET_SCREEN | LOG_TARGET_ERRORLOG;
*/ */
$cfg->log_backtrace_levels = LOG_LEVEL_WARN | LOG_LEVEL_ENVIRON; $cfg->log_backtrace_levels = LOG_LEVEL_WARN | LOG_LEVEL_ENVIRON;
/**
* @global int $cfg->error_reporting What level of errors to print to the Mahara logs. Gets passed directly
* to the PHP function "error_reporting()".
*
* NOTE: There are some limitations in this method, because it doesn't get called until several scripts
* have already been compiled: init.php, config.php, config-defaults.php, errors.php, and the file directly
* invoked in the URL. So, compile-time errors in those files (which includes most strict errors) will be
* unaffected by this setting.
*/
$cfg->error_reporting = E_ALL & ~E_STRICT;
/** /**
* @global int|bool $cfg->developermode Developer mode * @global int|bool $cfg->developermode Developer mode
* When set, the following things (among others) will happen: * When set, the following things (among others) will happen:
......
...@@ -49,9 +49,11 @@ define('DEVMODE_UNPACKEDJS', 8); ...@@ -49,9 +49,11 @@ define('DEVMODE_UNPACKEDJS', 8);
/**#@-*/ /**#@-*/
// Tell PHP about our error settings // Default error reporting settings. Some of these may be changed
error_reporting(E_ALL); // later in init.php after we've loaded config.php
set_error_handler('error'); $errorlevel = E_ALL & ~E_STRICT;
error_reporting($errorlevel);
set_error_handler('error', $errorlevel);
set_exception_handler('exception'); set_exception_handler('exception');
...@@ -390,7 +392,8 @@ function error ($code, $message, $file, $line, $vars) { ...@@ -390,7 +392,8 @@ function error ($code, $message, $file, $line, $vars) {
static $error_lookup = array( static $error_lookup = array(
E_NOTICE => 'Notice', E_NOTICE => 'Notice',
E_WARNING => 'Warning', E_WARNING => 'Warning',
// Not sure if these ever get handled here E_STRICT => 'Strict',
// These won't get handled here unless PHP's behavior changes
E_ERROR => 'Error', E_ERROR => 'Error',
// These three are not used by this application but may be used by third parties // These three are not used by this application but may be used by third parties
E_USER_NOTICE => 'User Notice', E_USER_NOTICE => 'User Notice',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment