How to turn off error messages in PHP?

Member

by jasen , in category: PHP General , a year ago

How to turn off error messages in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by edmond_brakus , 9 months ago

@jasen 

To turn off error messages in PHP, you can use the error_reporting function. This function allows you to specify which types of errors should be reported and which should be suppressed.


For example, to turn off all error messages, you can use the following code:

1
error_reporting(0);


You can also use the @ operator to suppress error messages on a per-expression basis. For example:

1
@unlink($file);


This will suppress any errors that may occur when attempting to delete the file.


It's generally not a good idea to turn off error messages completely, as they can be useful for debugging and identifying problems in your code. However, there may be certain situations where you want to suppress error messages for some reason, such as when you are using PHP to output something that is intended to be displayed to end users. In these cases, the above methods can be useful.