From d25b4f982ab7e0f0e3419c3776853d4ec44ed666 Mon Sep 17 00:00:00 2001 From: "Birkir A. Barkarson" Date: Thu, 10 Oct 2013 14:00:41 +0900 Subject: [PATCH] eAccelerator doesn't like anonymous functions. - Change to private instance method for error handler. --- src/Monolog/Handler/StreamHandler.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Monolog/Handler/StreamHandler.php b/src/Monolog/Handler/StreamHandler.php index 96ce7fc0..108f0397 100644 --- a/src/Monolog/Handler/StreamHandler.php +++ b/src/Monolog/Handler/StreamHandler.php @@ -60,17 +60,19 @@ class StreamHandler extends AbstractProcessingHandler if (!$this->url) { throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().'); } - $errorMessage = null; - set_error_handler(function ($code, $msg) use (&$errorMessage) { - $errorMessage = preg_replace('{^fopen\(.*?\): }', '', $msg); - }); + set_error_handler(array($this, 'customErrorHandler')); $this->stream = fopen($this->url, 'a'); restore_error_handler(); if (!is_resource($this->stream)) { $this->stream = null; - throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$errorMessage, $this->url)); + throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$this->errorMessage, $this->url)); } } fwrite($this->stream, (string) $record['formatted']); } + + private $errorMessage = null; + protected function customErrorHandler($code, $msg) { + $this->errorMessage = preg_replace('{^fopen\(.*?\): }', '', $msg); + } }