How to turn off warnings in PHP?

Member

by jerad , in category: PHP General , 8 months ago

How to turn off warnings in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by aubrey , 3 months ago

@jerad 

To turn off warning messages in PHP, you can use the error_reporting function. You can set the error_reporting function at the top of your script to turn off warning messages.


Here's an example:

1
error_reporting(E_ALL ^ E_WARNING);


This will turn off warning messages while still displaying other error messages.


Alternatively, you can use the ini_set function to set the display_errors configuration directive at runtime:

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


This will turn off all error messages, including warnings.


Keep in mind that it's generally a good idea to leave error messages enabled during development so that you can troubleshoot any issues that may arise. It's only recommended to turn off error messages in a production environment.