NYCPHP Meetup

NYPHP.org

[nycphp-talk] @include() affects all error_reporting !?!?

Adam Fields fields at surgam.net
Sat Jul 26 11:23:25 EDT 2003


On Sat, Jul 26, 2003 at 10:45:47AM -0400, George Webb wrote:
> 	Anyway my problem remains with the behavior of
> the @ operator for the include() statement.  The reason I
> am using the @ operator for include() is so that I can display
> my own error message, rather than the PHP's error message,
> if the file is unreadable.

As pointed out in the docs about error reporting, this behavior is
known, and the "right" way to approach this is to test for the
existence of the file and only include it if it exists:

if (is_file("nosuchfile.php")) {
   include_once("nosuchfile.php");
} 

> 	Also, the code needs to work in two different
> environments -- development and production.  In development,
> I want the include()'d file to turn ON error_reporting,
> while in production, I want it to turn error_reporting OFF.
> The include()'d file is the "config" file, so that is the
> natural place to put the error_reporting switch.

This is a slightly separate problem, which you should probably address
by using a custom error handler, then switching on hostname (or even
better, setting a flag based on hostname, then switching on the flag)
to tell if you should be generating production or development
messages.


-- 
				- Adam

-----
Adam Fields, Managing Partner, fields at surgam.net
Surgam, Inc. is a technology consulting firm with strong background in
delivering scalable and robust enterprise web and IT applications.
http://www.adamfields.com



More information about the talk mailing list