Error Management Operator Detection

Please tell me if this is correct. In my error handler, I should be able to detect when the @ error-control statement was used to suppress errors, because some external libraries (unfortunately) use it a lot. Script execution should continue as if you were not using custom error handlers.

When the at sign is used, PHP temporarily sets error_reporting to 0. Thus, at the beginning of the script, we set error_reporting to any value, but zero - now we can do some beautiful IF / ELSE magic. To avoid errors displayed in the external interface, we also set display_errors to 0, this will override error_reporting (but we can still use this value for magic).

<?php

ini_set('display_errors',0);
error_reporting(E_ALL);

function error_handler($errno, $errstr, $errfile, $errline)
{
    if (error_reporting()===0) return;
    else die();
}

set_error_handler('error_handler');

//This issues an error, but the handler will return and execution continues.
//Remove the at-sign and the script will die()
@file();

echo 'Execution continued, hooray.';
?>

, ? , .. ( ?)

+3
1

, script, @ , , , .

, taras :

, @ , :

  • , , , , @

  • . echo , NONE.

  • @? 0 . , , 0

set_error_handler, , , :

, 0, , @error-control.

, ; , (. )


, "" @( , , ), , (pecl, manual)

, php.ini( / , ):

scream.enabled = 1

@.


( manual):

<?php
// Make sure errors will be shown
ini_set('display_errors', true);
error_reporting(E_ALL);

// Disable scream - this is the default and produce an error
ini_set('scream.enabled', false);
echo "Opening http://example.com/not-existing-file\n";
@fopen('http://example.com/not-existing-file', 'r');

// Now enable scream and try again
ini_set('scream.enabled', true);
echo "Opening http://example.com/not-existing-file\n";
@fopen('http://example.com/another-not-existing-file', 'r');
?>

:

Opening http://example.com/not-existing-file
Opening http://example.com/not-existing-file

Warning: fopen(http://example.com/another-not-existing-file): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in example.php on line 14


, ( ), /, @operator extensivly...

+1
source

Source: https://habr.com/ru/post/1715264/


All Articles