Error Trapping with include and require
Moderator: General Moderators
Error Trapping with include and require
I'm wanting to trap and handle my own errors. The problem I'm running into is with require and include. It appears that it doesn't return anything. Is there anyway to check to see if a file has been included? I know I can use @ to suppress the php fatal error, but I need to know how to evalute it's inclusion so I can handle the error myself.
try
Code: Select all
<?php
$i = @include('not_a_file.php');
echo ($i===FALSE) ? 'error' : 'success';
?>Weird results.
Thanks Volka,
I tried your code and got weird results, so I tested it further to try and nail down the problem.
It appears that when I use @require_once(), if a fatal_error occurs, PHP will suppress the error, but I can't send anything to the output buffer after that. It appears to just end the script and outputs nothing.
Any idea what's happening. Im running 4.0.6 in cgi mode.
Thanks
I tried your code and got weird results, so I tested it further to try and nail down the problem.
It appears that when I use @require_once(), if a fatal_error occurs, PHP will suppress the error, but I can't send anything to the output buffer after that. It appears to just end the script and outputs nothing.
Any idea what's happening. Im running 4.0.6 in cgi mode.
Thanks
Much Thanks
Makes total sense.
Much thanks Volka
Much thanks Volka
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Another approach could be to test to see if a file exists (using file_exists()) if it doesn't then don't try and include it.
Mac
Mac