Page 1 of 1

How to catch error from include "file.php"?

Posted: Mon Sep 22, 2008 11:44 am
by ericm
I have a simple template system that uses extract, ob_start, include, and ob_get_contents. I've ran into several instances where errors in the template has resulted in a blank page being display. This is, of course, unless I remove the error suppressor "@" from the include line, which gives me the parse error message. What I would prefer is to hide the specific error, but catch it and throw my own custom error message. Unfortunately I haven't figured out just how to do that. I've tried...

Code: Select all

if(!@include("file.php")) {...}
...and...

Code: Select all

if((@include "file.php") === false) {...}
Is there a way to still use @include and somehow catch the error? I think error_get_last() is the answer, but I first need to figure out how to get @include to trigger false.

Re: How to catch error from include "file.php"?

Posted: Mon Sep 22, 2008 6:23 pm
by yacahuma
there is no reason to have errors in your includes. You should fix them and stop using the @include the @ is good for some very specific calls(like curl, and some file system stuff) not for includes. IMHO