From cb8aff323e884b217b177a25aaf3c3b883c2c2ed Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 11 Jun 2014 16:52:49 +0200 Subject: [PATCH] [Debug] work-around https://bugs.php.net/61272 --- .../Component/Debug/ExceptionHandler.php | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Component/Debug/ExceptionHandler.php b/src/Symfony/Component/Debug/ExceptionHandler.php index 5e841e2fab239..6c12979d6e0cd 100644 --- a/src/Symfony/Component/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/Debug/ExceptionHandler.php @@ -36,7 +36,8 @@ class ExceptionHandler private $debug; private $charset; private $handler; - private $caughtOutput = 0; + private $caughtBuffer; + private $caughtLength; public function __construct($debug = true, $charset = 'UTF-8') { @@ -94,29 +95,25 @@ public function handle(\Exception $exception) return; } - $caughtOutput = 0; + $caughtLength = $this->caughtLength = 0; - $this->caughtOutput = false; ob_start(array($this, 'catchOutput')); $this->failSafeHandle($exception); - if (false === $this->caughtOutput) { - ob_end_clean(); + while (null === $this->caughtBuffer && ob_end_flush()) { + // Empty loop, everything is in the condition } - if (isset($this->caughtOutput[0])) { + if (isset($this->caughtBuffer[0])) { ob_start(array($this, 'cleanOutput')); - echo $this->caughtOutput; - $caughtOutput = ob_get_length(); + echo $this->caughtBuffer; + $caughtLength = ob_get_length(); } - $this->caughtOutput = 0; + $this->caughtBuffer = null; try { call_user_func($this->handler, $exception); - - if ($caughtOutput) { - $this->caughtOutput = $caughtOutput; - } + $this->caughtLength = $caughtLength; } catch (\Exception $e) { - if (!$caughtOutput) { + if (!$caughtLength) { // All handlers failed. Let PHP handle that now. throw $exception; } @@ -388,7 +385,7 @@ private function formatArgs(array $args) */ public function catchOutput($buffer) { - $this->caughtOutput = $buffer; + $this->caughtBuffer = $buffer; return ''; } @@ -398,9 +395,9 @@ public function catchOutput($buffer) */ public function cleanOutput($buffer) { - if ($this->caughtOutput) { + if ($this->caughtLength) { // use substr_replace() instead of substr() for mbstring overloading resistance - $cleanBuffer = substr_replace($buffer, '', 0, $this->caughtOutput); + $cleanBuffer = substr_replace($buffer, '', 0, $this->caughtLength); if (isset($cleanBuffer[0])) { $buffer = $cleanBuffer; }