Marin Kovacevic Marin Kovacevic - 1 month ago 9
PHP Question

PHP: despite disabling all errors, copy() error message still displayed on page

I have:

ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);


It seems to work but when I use
copy()
function and try to copy to directory with denied access the error is displayed on the page itself. I don't need it. But I can't intercept
copy()
's errors. I tried
error_get_last()
and
try...catch (Exception $e)
but still can't intercept it? How can I disable showing copy errors on page and how to intercept them in code?

Answer

from runtime it is better (and more reliable) to use:

error_reporting(0);

see: http://php.net/manual/en/function.error-reporting.php, so-doc for more info.

also you can suppress any errors regarding of reporting level by prefixing expression with @:

@copy(...)

see: http://php.net/manual/en/language.operators.errorcontrol.php for more info, also note what this cause a performance drop and causes expression to return boolean false if error occured, regardless of its original return type.