Let us assume that an easy snippet is used for templating and is using output control (ob)
public function capture($file, array $args = array())
{
extract($args, EXTR_SKIP);
ob_start();
require $file; //'foo.php'
return ob_get_clean();
}
And foo.php
that has an error (handled by an error handler and shutdown handler)
<?php
echo "before";
echo $someVariable; //$someVariable is undefined here
echo "after";
Output
before <- would like to avoid
some message from the error handler
The question: is it possible to avoid any output from the file upon error?
Yes,
-
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.
Errors inside of output buffer
How to see php error in included file while output buffer? (@marc-b - probably it isn't)
I understand that you should not want to handle this kind of errors in your own code since it has to be clean & tested but still you might get some, e.g. typo, undefined variable, etc.