Drush overrides PHP's error_reporting settings defined in the php.ini. This happens in drush_errors_on():
$errors =& drush_get_context('DRUSH_ERROR_REPORTING', E_ALL ^ E_NOTICE);
$errors = error_reporting($errors);
There and drush_errors_off() is the only time that context is used, so in effect, that piece of code overrides the builtin error_reporting() settings with E_ALL ^ E_NOTICE, which yields deprecation warnings and all bunch of silly stuff.
I think a better way to do this would be:
$errors =& drush_get_context('DRUSH_ERROR_REPORTING', error_reporting());
$errors = error_reporting($errors);
drush_errors_off() should also be changed to:
$errors =& drush_get_context('DRUSH_ERROR_REPORTING', error_reporting());
$errors = error_reporting(0);
... so that the default DRUSH_ERROR_REPORTING context is set correctly regardless of which one is called first.
Note that a workaround for this is to have a hook_drush_init() implementation that explicitely sets that context for you beforehand. But by POLA (Principle Of Least Astonishment), I think we should respect existing error_reporting settings.
This is coming from #1075322: Creating a site gives many "Function ereg() is deprecated file.inc:941" errors and a broken site and relatives.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 1129332_error_reporting_improved.patch | 1.66 KB | anarcat |
| #2 | 1129332_error_reporting.patch | 1.7 KB | anarcat |
| #1 | test_errors.txt | 1.42 KB | anarcat |
Comments
Comment #1
anarcat commentedHere is a test script to demonstrate how the builtin errors are overriden.
Comment #2
anarcat commentedAnd here's a patch that fixes it all. The code is much more readable to me that way too.
The output of the test script before:
the output of the test script after:
note, for clarity, that the "correct" error reporting level is 22527:
Patch has more information regarding the logic of the change.
Note that another improvement we could do we be to accept arguments in drush_errors_on() to allow changing the default error level, because 'just set error_reporting()' works, but only if drush_errors_on/off was never called.
Comment #3
anarcat commentedAnd this second patch does just that. This patch is completely optional and not necessary to fix the actual bug here. Just an API improvement.
It does how depend on the other one.
Comment #4
anarcat commentedIt seems nobody objects here, I'll just commit this after some more stress tests on my side.
Comment #5
msonnabaum commentedLooks reasonable to me.
Comment #6
moshe weitzman commentedNo objection. Just coding standards stuff. Code comments should start with capital letter and end in a period. Also,
} else {does not follow coding standardsComment #7
anarcat commentedI have fixed the commits to follow the coding standards, thanks!
Pushed to master.
Comment #9
j0nathan commentedSubscribing (archives).
Comment #10
anarcat commentedActually, I think that we should refactor this into 4.x - it's a small patch that doesn't break anything... without this, I need to patch core to install openatrium with aegir.
the two patches i want to merge into 4.x are:
d001faeb3f00f2c0a60f69213272166f6a1c14e2
ce7c0a21eee7bda270b56d4dfe22c48f1afb132a
Comment #11
anarcat commentedAnother workaround has been posted in #1120848: Don't log E_DEPRECATED errors OR check error_reporting(), but I think we should still merge those in for completeness.
Comment #12
tinefin commentedsubscribing
Comment #13
msonnabaum commentedThis looks reasonable to me. Backported.