Forum Moderators: coopster

Message Too Old, No Replies

All PHP Warnings now throw Exceptions on server!?

Affects all sites on the same server.

         

penders

2:53 pm on Jan 21, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Ok, this is a bit weird... something must have changed (although to my knowledge nothing has) on my development server that now results in all warnings (E_WARNING, E_USER_WARNING) being thrown as exceptions (standard "Exception"). This affects ALL sites on the server!?

Not that long ago, regular warnings (E_WARNING) were triggered as normal.

I can override this if I set my own error handler, but otherwise there is no custom error handler being set. In fact, set_error_handler() returns NULL which indicates that the built-in error handler is being used. (But the built-in error handler should not be throwing exceptions!?)

I have recently been using mysqli_report to throw mysqli_sql_exception instead of warnings for mysqli errors. However, turning this off (MYSQLI_REPORT_OFF) has no effect on this problem. Base "Exceptions" (not a mysqli_sql_exception) are still thrown for non-mysqli warnings.

// Enables mysqli errors to be thrown as mysqli_sql_exception instead of warnings
mysqli_report(MYSQLI_REPORT_ALL);


Any ideas?!

penders

11:06 pm on Jan 21, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Long story short... Yes, it was to do with mysqli_report() / mysqli_driver->report_mode and notably with the version of PHP (5.2.6) running on the server.

In PHP before 5.2.15 (and 5.3.4) the report_mode is set per-process, rather than per-request, so it is important to set this back to MYSQLI_REPORT_OFF (OO style seems to work better in this respect) when the script finishes.

However, the fact that this caused other E_WARNINGs and E_USER_WARNINGs to be thrown as exceptions seems to be a bug in my opinion (although I couldn't find anything documented). Anyway, in later versions of PHP (tested 5.3.26) it is not a problem.