Nikoole
Nikoole

Reputation: 4603

Notices in PHP. How to did not show them?

I has function which deleting the file. It is my code:

echo error_reporting();     // got 32767 = E_ALL, yes?
ini_set('display_errors',0);
if(unlink($file) == false){
    echo "Error";
}

And I am getting the following error:

string(274) "PROBLEM unlink(/path/to/file.mp4): Permission denied in /path/to/script.php on line 1226

How can I log my errors on log file, but not on the screen?

Upvotes: 0

Views: 71

Answers (5)

Nikoole
Nikoole

Reputation: 4603

It was var_dump() on other script which catching errors and show it on screen.

Upvotes: 0

Robert
Robert

Reputation: 20286

You can use your own error handler with function set_error_handler()

You can write logging in the function passed to set_error_handler()

This function has also param called error_types where you can provide what kind of errors you want to handle. It's up to you if you display them or not.

I won't write about other options because they were already mentioned by others.

Upvotes: 1

BIT CHEETAH
BIT CHEETAH

Reputation: 1200

→ Try this:

This will work at runtime:

     ini_set( 'display_errors', '0' );

This will stop errors from being displayed but they will still be logged. This will stop both:

     error_reporting(0); // Will stop both error displaying and reporting to screen

Upvotes: 0

ranieuwe
ranieuwe

Reputation: 2296

The reason why it doesn't work is because in PHP 5.2.4 and up the variable has changed from boolean to string. Set display_errors to 'stderr' instead.

Upvotes: 0

Rohit Choudhary
Rohit Choudhary

Reputation: 2269

you can use error_log() and for suppress the error in frontend you can use error_reporting(0)

Upvotes: 0

Related Questions