php - How to ignore only warnings with a specific message? -
as workaround another issue set error handler only specific warning. should check whether warning starts string, , if not should hand warning on original handler.
what i've got far:
function filesize_for_url_ignoring_error_handler($severity, $message, $file, $line, $context) { if (strpos($message, 'warning: filesize(): stat failed https://') === 0) { return; } restore_error_handler(); throw new errorexception($message, e_warning, $severity, $file, $line); } set_error_handler('filesize_for_url_ignoring_error_handler', e_warning); $file = file_save($file); restore_error_handler(); however, there seems several problems:
- i can't override error handler single error type. i've tried passing
e_error,~e_warning,e_all,0error typeset_error_handler, seems setting error handler given type removes error handlers other types. correct? can work around setting error handler error types. - i don't know how handle warning original error handler if doesn't match expected message. throwing
errorexceptionnot right thing - results in full stacktrace , message not end in drupal watchdog log. runningtrigger_errorinstead doesn't work either - can see trigger called (usingerror_log) message doesn't end in watchdog log.
using drupal 7.56 , php 5.4.
90% solved writing custom error handler calls original error handler if message doesn't match:
function filesize_for_url_ignoring_error_handler($severity, $message, $file, $line, $context) { global $originalerrorhandler; if (strpos($message, 'filesize(): stat failed https://') !== 0) { $originalerrorhandler($severity, $message, $file, $line, $context); } } class […] { public function […] { $originalerrorhandler = set_error_handler('filesize_for_url_ignoring_error_handler'); $file = file_save($file); restore_error_handler(); } } now messages not start "filesize(): stat failed https://" still logged in file_save. issue watchdog log shows message originating in filesize_for_url_ignoring_error_handler, won't mark solved yet in case knows how fix (and ideally avoid using global variable).
Comments
Post a Comment