Page 1 of 1

Detecting failure of include/require

Posted: Sat May 10, 2008 1:17 am
by Apollo
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:

Code: Select all

@require("somefile.php") or die("File not found :(");
I know I can define some constant in the include, and then in the main file:

Code: Select all

@include("somefile.php");
if (!defined(constant)) die("My favorite error message");
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?

Re: Detecting failure of include/require

Posted: Sat May 10, 2008 1:37 am
by RobertGonzalez
http://us.php.net/include/ Check out example #5