I'm trying to guess how to achieve scripts inclusions and keep it throwing errors and warnings. I've got the following code:
if(!@include_once "myscript.php") doSomething();
This will supress "include" warning error if script file doesn't exist and it will include the script file if it exists. The problem comes when an error is generated in "myscript.php". For example, I've got another require_once in "myscript.php" and I caused an error by setting a wrong path. Errors are not displayed and code after that call is not reached/executed.
Is there a way I can supress just the file inclusion errors but not errors generated in the included script? If not, what other way can I use to achieve the target behaviour?
I've thought about using file_exists function to check if script file exists and then include it if TRUE but I'm looking for the simplest way.
I'll put a practical example since it's difficult to understand the actual question:
Imagine that we want to manage a file system that will be used by a user and we need to check whether the user has created a file because that file will be included after the check, but we want to handle the inclusion warning/error so we can show a message or log the warning in a custom log file. First function that comes to our mind is to use file_exists and then include that file. Well, by using @include both functions are performing, it will check if the file exists and it will include the file and that's what I'm researching, the simplest way of doing an action. This way of doing it has an undesired behaviour: it supresses the errors/warnings generated by the included file, not only the inclusion errors/warnings itself. Other reason to avoid file_exists when you are checking if a file exists before trying to include it may be that the way both functions look for a file are different and they may generate different results because of include_path. Is this correct?
file_exists()is not simple? :Pfile_existsandinclude. It's better to use just one function if possible :D