Detecting failure of include/require
Posted: Sat May 10, 2008 1:17 am
Sometimes I want to require a file, but not show the default PHP error message (with the path and everything) when it fails. But whit an @ in front of it (to suppress error message), the scripts just stops with no error at all.
Is there a way to do something like this:
I know I can define some constant in the include, and then in the main file:
This is what I currently do in such cases.
Is there an even simpler way to react on a failed include or require, that does not depend on custom defines in the included file?
Is there a way to do something like this:
Code: Select all
@require("somefile.php") or die("File not found :(");Code: Select all
@include("somefile.php");
if (!defined(constant)) die("My favorite error message");Is there an even simpler way to react on a failed include or require, that does not depend on custom defines in the included file?