NYCPHP Meetup

NYPHP.org

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

George Webb gw.nyphp at gwprogramming.com
Sat Jul 26 10:45:47 EDT 2003


Good morning all.  Sorry I crashed last night before this
thread got under way.

	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.

	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.

	Unfortunately, I can't seem to call this config file
with @include() and have the error_reporting change stick.
So what I could do is to manually turn off error_reporting
just before the include() call ... or else just deal with
having PHP's ugly error message before my nice error message
whenever the config file is missing.  -OR- I could simply
define another config parameter and manually set error_reporting
to that.

	I actually have done the latter; here is the code:

if ( ! @include ( 'StoreConfig.php' ) )
        die ( '<B>Error:</B> Store not configured (no StoreConfig.php file)' );
error_reporting ( ERROR_REPORTING ); //hack for error_reporting not working in @include'd file


	Of course I would have rather simply called error_reporting()
directly in StoreConfig.php; then we wouldn't have needed this
extra ERROR_REPORTING constant.

	Any further suggestions?

	Should I report this to bugs.php.net?  Does anyone think
the @include/error_reporting behavior is NOT a bug?  

	Thanks again for your suggestions and good ideas about
error reporting in general.


Best, George.

George Webb
gw.nyphp at gwprogramming.com



More information about the talk mailing list