I am looking for best solution how to disable known warnings (and irrelevant warnings for my script) reported from an included file.
Short example of the included file:
$ cat incl_file.php
<?php
error_reporting(E_ALL);
ini_set("display_errors", "on");
$x = $y;
?>
Example of the desired code (which doesn't prevent displaying errors from the included file)
$ cat main2.php
<?php
error_reporting(E_ALL);
ini_set("display_errors", "on");
@include_once "incl_file.php";
$d=$e;
print "main_file\n";
?>
The output:
$ php main2.php
Notice: Undefined variable: y in /tmp/php_hack/incl_file.php on line 6
Notice: Undefined variable: e in /tmp/php_hack/main2.php on line 7
main_file
The Following "workaround" works but I'm not satisfied with it's mess:
<?php
function myErrorHandler($errno, $errstr, $errfile, $errline) {
if (!(error_reporting() & $errno)) {
// This error code is not included in error_reporting
return;
}
//print "called $errstr\n";
/* Don't execute PHP internal error handler */
return true;
}
set_error_handler("myErrorHandler");
error_reporting(0);
ini_set("display_errors", "off");
include_once "incl_file.php";
restore_error_handler();
error_reporting(E_ALL);
ini_set("display_errors", "on");
$d=$e;
print "main_file\n";
?>
Output:
$ php main.php
Notice: Undefined variable: e in /tmp/php_hack/main.php on line 24
main_file
If the included file doesn't have
error_reporting(E_ALL);
ini_set("display_errors", "on");
then the @ operator works as expected...