title: Output buffer error handling
body: <p>Let us assume that an easy snippet is used for templating and is <a href="http://php.net/manual/en/ref.outcontrol.php" rel="nofollow noreferrer">using output control (ob)</a></p>
  
  <pre><code>public function capture($file, array $args = array())
  {
      extract($args, EXTR_SKIP);
  
      ob_start();
  
      require $file; //'foo.php'
  
      return ob_get_clean();
  }
  </code></pre>
  
  <p>And <code>foo.php</code> that has an error (handled by an <a href="http://php.net/manual/en/function.set-error-handler.php" rel="nofollow noreferrer">error handler</a> and <a href="http://php.net/manual/en/function.register-shutdown-function.php" rel="nofollow noreferrer">shutdown handler</a>)</p>
  
  <pre><code>&lt;?php
  
  echo "before";
  echo $someVariable; //$someVariable is undefined here
  echo "after";
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>before &lt;- would like to avoid
  some message from the error handler
  </code></pre>
  
  <p><strong>The question: is it possible to avoid any output from the file upon error?</strong></p>
  
  <p>Yes,</p>
  
  <ul>
  <li><p>there are similar questions out there that I read/analysed but none of them gave me a clear answer whether this is or isn't.</p>
  
  <p><a href="https://stackoverflow.com/questions/1979588/errors-inside-of-output-buffer">Errors inside of output buffer</a></p>
  
  <p><a href="https://stackoverflow.com/questions/25795647/how-to-see-php-error-in-included-file-while-output-buffer">How to see php error in included file while output buffer?</a> (@marc-b - probably it isn't)</p></li>
  <li><p>I understand that you should not want to handle this kind of errors in your own code since it has to be clean &amp; tested but still you might get some, e.g. typo, undefined variable, etc.</p></li>
  </ul>