You are here

function util_error_levels in Util 7

Same name and namespace in other branches
  1. 6.3 util.module \util_error_levels()

Show the current error reporting level.

1 string reference to 'util_error_levels'
util_menu in ./util.module
Implements hook_menu().

File

./util.module, line 89
Helper Utilities for your Drupal site.

Code

function util_error_levels($current = NULL) {
  $e_all = 2047;
  $levels = array(
    'E_ERROR ' => array(
      'value' => 1,
      'desc' => 'Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted. ',
      'note' => ' ',
    ),
    'E_WARNING ' => array(
      'value' => 2,
      'desc' => 'Run-time warnings (non-fatal errors). Execution of the script is not halted. ',
      'note' => ' ',
    ),
    'E_PARSE ' => array(
      'value' => 4,
      'desc' => 'Compile-time parse errors. Parse errors should only be generated by the parser. ',
      'note' => ' ',
    ),
    'E_NOTICE ' => array(
      'value' => 8,
      'desc' => 'Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script. ',
      'note' => ' ',
    ),
    'E_CORE_ERROR ' => array(
      'value' => 16,
      'desc' => 'Fatal errors that occur during PHPs initial startup. This is like an E_ERROR, except it is generated by the core of PHP. ',
      'note' => 'since PHP 4',
    ),
    'E_CORE_WARNING ' => array(
      'value' => 32,
      'desc' => 'Warnings (non-fatal errors) that occur during PHPs initial startup. This is like an E_WARNING, except it is generated by the core of PHP. ',
      'note' => 'since PHP 4',
    ),
    'E_COMPILE_ERROR ' => array(
      'value' => 64,
      'desc' => 'Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine. ',
      'note' => 'since PHP 4',
    ),
    'E_COMPILE_WARNING ' => array(
      'value' => 128,
      'desc' => 'Compile-time warnings (non-fatal errors). This is like an E_WARNING, except it is generated by the Zend Scripting Engine. ',
      'note' => 'since PHP 4',
    ),
    'E_USER_ERROR ' => array(
      'value' => 256,
      'desc' => 'User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error(). ',
      'note' => 'since PHP 4',
    ),
    'E_USER_WARNING ' => array(
      'value' => 512,
      'desc' => 'User-generated warning message. This is like an E_WARNING, except it is generated in PHP code by using the PHP function trigger_error(). ',
      'note' => 'since PHP 4',
    ),
    'E_USER_NOTICE ' => array(
      'value' => 1024,
      'desc' => 'User-generated notice message. This is like an E_NOTICE, except it is generated in PHP code by using the PHP function trigger_error(). ',
      'note' => 'since PHP 4',
    ),
  );
  if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
    $levels += array(
      'E_STRICT ' => array(
        'value' => 2048,
        'desc' => 'Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code. ',
        'note' => 'since PHP 5',
      ),
    );
  }
  if (version_compare(PHP_VERSION, '5.2.0', '>=')) {
    $e_all = 6143;
    $levels += array(
      'E_RECOVERABLE_ERROR ' => array(
        'value' => 4096,
        'desc' => 'Catchable fatal error. It indicates that a probably dangerous error occured, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle (see also set_error_handler()), the application aborts as it was an E_ERROR. ',
        'note' => 'since PHP 5.2.0',
      ),
    );
  }
  if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
    $e_all = 30719;
    $levels += array(
      'E_DEPRECATED ' => array(
        'value' => 8192,
        'desc' => 'Run-time notices. Enable this to receive warnings about code that will not work in future versions. ',
        'note' => 'since PHP 5.3.0',
      ),
      'E_USER_DEPRECATED ' => array(
        'value' => 16384,
        'desc' => 'User-generated warning message. This is like an E_DEPRECATED, except it is generated in PHP code by using the PHP function trigger_error(). ',
        'note' => 'since PHP 5.3.0',
      ),
    );
  }
  $levels += array(
    'E_ALL ' => array(
      'value' => $e_all,
      'desc' => 'All errors and warnings, as supported, except of level E_STRICT. ',
      'note' => '<em>30719 in PHP 5.3.x, 6143 in PHP 5.2.x, 2047 previously.</em>',
    ),
  );
  if (!$current) {
    $current = error_reporting();
  }
  $output = "<h2>Current Error Reporting Value: {$current}</h2>";
  $nots = "<h2>Not Using</h2>";
  foreach ($levels as $level => $data) {

    // TRUE/FALSE would catch E_ALL; this does not, unless correct.
    if (($current & $data['value']) == $data['value']) {
      $output .= '<p>' . $level . '  <small>' . $data['desc'] . ' ' . $data['note'] . '</small>' . '</p>';
    }
    else {
      $nots .= '<p>' . $level . '  <small>' . $data['desc'] . ' ' . $data['note'] . '</small>' . '</p>';
    }
  }
  return $output . $nots;
}