How to turn off warnings in PHP?

Member

by jerad , in category: PHP General , 2 years ago

How to turn off warnings in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by aubrey , 2 years 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.

Member

by lottie , a year ago

@jerad 

It's worth noting that turning off warning messages can hide potential issues in your code, and it is generally not recommended in a production environment. It is better to fix the underlying issues causing the warnings instead of suppressing them.