NYCPHP Meetup

NYPHP.org

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

George Webb gw.nyphp at gwprogramming.com
Fri Jul 25 20:11:17 EDT 2003


Good Evening!  Having trouble understanding the @ operator,
when used with include(), i.e. @include('file.php') .

	I *thought* that @include would simply suppress the
warning generated if the included file is missing.  However,
what seems to happen is more complicated:

	@include('file.php') causes error_reporting to get
turned completely OFF for the duration of the included file.
Then, even worse, when the included file ends, error_reporting
is restored to its previous state, from *before* the include
was called.  To illustrate:



/*** start of file.php ***/
    error_reporting(0);
    echo ini_get('error_reporting');  //prints 0
/*** end of file.php ***/



/*** start of script.php ***/
    error_reporting(E_ALL);
    echo ini_get('error_reporting');  //prints 2047

    @include('file.php'); // this should set error_reporting
                          // to zero, but it doesn't


    echo ini_get('error_reporting');  //prints 2047

/*** end of script.php ***/


	If you remove the leading '@' from '@include', the
desired behavior occurs, which is that changes to error_reporting
in the included file will take effect in the calling script.

	I have seen this behavior in PHP versions 4.0.8 through
4.3.2.  Does anyone agree that this is a bug?  In any case,
how can we elegantly work-around it?  I need to be able to control
error reporting from the included file, which may or may not exist.
Thanks!


Best, George.

George Webb
gw.nyphp at gwprogramming.com



More information about the talk mailing list