[thelist] one-line suppress PHP warnings?

kasimir-k kasimir.k.lists at gmail.com
Tue Mar 25 18:34:54 CDT 2008


Stephen Rider scribeva in 2008-03-25 22:46:
> Is there a way to write the include so that if the file is _not_ found  
> it will NOT write an error to the logs?
> 
> I was doing a file_exists(), but I'm trying to streamline as much as  
> possible -- this would reduce three lines to one.

Overall I think this is not the best spot to start streamlining. Nice 
and maintainable code makes it easy to spot later one when something is 
done non-default way - and warning on non-existent include file is a 
reasonable default.

But if you really want to do it, I can come up with two ways.

1. @include($incfile);
You won't get any errors from the $incfile either - which may not be 
what you'd want.

2. Write your own error handler[0] and test if the error message 
contains text "[function.include]" and only log if it doesn't. This 
might require some tweaks with your error logging that I can't think of now.

.k

[0]http://php.net/set-error-handler



More information about the thelist mailing list