Skip to content

Commit

Permalink
Prevent endless recursion in error handler. Fixes #206
Browse files Browse the repository at this point in the history
  • Loading branch information
rosell-dk committed Aug 2, 2019
1 parent 4ea37ba commit 37e0094
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Convert/Converters/BaseTraits/WarningLoggerTrait.php
Expand Up @@ -79,10 +79,18 @@ public function warningHandler($errno, $errstr, $errfile, $errline)
$this->logLn($msg, 'italic');
$this->logLn('');

//echo 'previously defined handler:' . print_r($this->previousErrorHandler, true);

if (!is_null($this->previousErrorHandler)) {
return call_user_func($this->previousErrorHandler, $errno, $errstr, $errfile, $errline);
// If previousErrorHandler is this very error handler, exit to avoid recursion
// (this could happen if ::activateWarningLogger() were called twice)
if (
is_array($this->previousErrorHandler) &&
isset($this->previousErrorHandler[0]) &&
($this->previousErrorHandler[0] == $this)
) {
return false;
} else {
return call_user_func($this->previousErrorHandler, $errno, $errstr, $errfile, $errline);
}
} else {
return false;
}
Expand Down

0 comments on commit 37e0094

Please sign in to comment.