Check if an include (or require) exists
I believe file_exists
does work with relative paths, though you could also try something along these lines...
if(!@include("script.php")) throw new Exception("Failed to include 'script.php'");
... needless to say, you may substitute the exception for any error handling method of your choosing. The idea here is that the if
-statement verifies whether the file could be included, and any error messages normally outputted by include
is supressed by prefixing it with @
.
Check out the stream_resolve_include_path function,it searches with the same rules as include().
http://php.net/manual/en/function.stream-resolve-include-path.php