processwire / processwire-issues

ProcessWire issue reports.
45 stars 2 forks source link

$config->debugIf doesn't behave exactly like $config->debug #1677

Closed nurkka closed 1 year ago

nurkka commented 1 year ago

Short description of the issue

When using $config->debugIf to turn on debug mode, no PHP deprecated errors are displayed or logged.

Expected behavior

When using $config->debugIf , the behaviour should be exactly the same as with $config->debug = true;

Actual behavior

ProcessWire sets error_reporting to not show any php deprecated errors before it evaluates the debugIf setting.

Optional: Suggestion for a possible fix

In /wire/core/ProcessWire.php the following code block

// If debug mode is on then echo all errors, if not then disable all error reporting
if($config->debug) {
    error_reporting(E_ALL | E_STRICT);
    ini_set('display_errors', 1);
} else {
    error_reporting(0);
    ini_set('display_errors', 0);
}

should be moved below the code block, where debugIf is evaluated.

Steps to reproduce the issue

  1. Make sure that your server/webhosting is configured to show and/or log php errors, and that it allows PHP to decide, if errors are shown or hidden
  2. In /site/config.php, set $config->debug = false
  3. In /site/config.php, set $config->debugIf = 'YOUR_IP_ADDRESS'; , where YOUR_IP_ADRESS must be your actual IP-adress
  4. Put trigger_error( 'This is a deprecated error', E_USER_DEPRECATED); somewhere on your page template, where it will be executed, when the page is displayed
  5. Reload the page in the browser
  6. The triggered error won’t be displayed nor logged anywhere

Setup/Environment

ryancramerdesign commented 1 year ago

@nurkka Thanks, I've pushed a fix for this issue.

nurkka commented 1 year ago

@ryancramerdesign Thanks for the quick fix – and thanks again for ProcessWire :-)