W3docs

How to Remove Warning Messages in PHP

In this short tutorial, we are going to represent to you a solution to a common PHP issue: how to remove warning messages easily.

At times, you may want to hide warning messages from the browser. In this snippet, we show two efficient ways to handle that.

Use error_reporting()

The first efficient way is to apply error_reporting() .

So, to skip the warning messages, just run the code below:

skip warning messages php

<?php
error_reporting(E_ERROR | E_PARSE);
ini_set('display_errors', 0);

Note: error_reporting() only filters which errors are reported. To actually hide them from the browser, you must also control the display_errors setting.

Use the @ Operator

Here is another simple method of removing warning messages with PHP. All you need to do is to put @ in front of the function you intend to run.

Here is an example:

remove warning message with @

<?php
@theFunctionHere();

How error_reporting() Works

In PHP, error_reporting() error_reporting() E_ERROR E_PARSE error_reporting() error_reporting() primarily controls runtime error reporting; compile-time errors are handled during script compilation.

Best practice: Suppressing warnings globally is generally discouraged. It is better to fix the root cause of the warning or log errors to a file using error_log() instead.