barbushin / php-console

Handle PHP errors, dump variables, execute PHP code remotely in Google Chrome
https://chrome.google.com/webstore/detail/php-console/nfhmhhlpfleoednkpnnnkolmclajemef
MIT License
1.34k stars 283 forks source link

sorely missing option to change error reporting mode during code execution #135

Open subpardaemon opened 7 years ago

subpardaemon commented 7 years ago

hi,

just jump to the tl;dr part for the actual problem.

lately i've ran into a problem where an external package that is vital for our services started spewing deprecation warnings like there is no tomorrow.

i was told that until there is a fix (which they're working on now) i should just turn off deprecation warnings.

i'm using phpconsole, and namely, in the old compatibility mode (hadn't had time to update all my dependent codes to the new version). i'm also a very pickish person when it comes to errors, so i like to see all errors (notices, warnings, deprecations, etc) reported. that is one of the reasons why i love phpconsole.

so the obvious solution not to crash my system (i'd had the system run out of allowed memory because of the sheer number of deprecation warnings) is to turn off deprecation warnings ONLY if the execution requires the external package (which is like 10% of the time, but then it's vital -- it's a payment interface). of course, setting error_reporting(..) never worked as by that time phpconsole's internal settings were in effect.

after a bit of investigation, i've arrived at this solution:

TL;DR

to change error reporting level mid-execution, i'd do

PhpConsole::getInstance()->getHandler()->setErrorsHandlerLevel(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);

and i was rewarded with a nice little exception saying that i need to set it BEFORE initialising phpconsole. haha. which is of course impossible because at that point in the code i have no idea whether i need to run the troublesome extension or not.

so i changed line 138 in Handler.php to comment out $this->checkIsCalledBeforeStart(); and now everything works as expected.

question: why not skip this condition check altogether? is there a reason why it's so bad to change error reporting level mid-run?

thanks,a