Technology

What Is The Most Useful Method To Turn Off or Remove Warning/Error Messages In PHP?

You must have surely seen a warning message output to the browser as soon as you run your PHP script and you may also want to turn off that error message. Although, it is much better to get to the cause of the problem and fix that, but you can also remove a warning message in PHP through the use of a simple function in PHP, known as the error_reporting.

  • Turn off warnings in PHP Using the error_reporting function

Basically, the error_reporting function in PHP allows you to set the type of error reporting that you want. Now the question arises that how does the error_reporting function works? The answer is simple. You just need to pass in the type of errors that you want to have reported on the page to the error_reporting function, however, you need to pass in constants, which are text fields that convert to numbers.

The function of E_PARSE constant is to inform PHP about compile time parse errors that they should be displayed and reported on the page. As you obviously want to know about any compile time errors, thus you should pass this constant to the function. Now the E_ERROR constant informs PHP regarding the details of any fatal run-time errors that they should be displayed and reported – this is also something you definitely want, because you should always know about the cause of any fatal run-time error.

What is the code to turn off error messages in PHP?

If you want to remove or turn off warning messages in PHP, you simply have to place the below mentioned line of code before the code, which is responsible to display the warning in PHP. Make sure to place the code before the offending code, because if you place it after it, then it will not work and would be unable to suppress the warning message that is being displayed.

Following is the line of code to use that you have to place before the offending code:

error_reporting(E_ERROR | E_PARSE);

 

Leave a Reply