Supressing Error Messages in PHP

Every once in awhile PHP decides to throw some errors.  Usually it’s because you didn’t do something right, but what if it’s throwing errors anyways?  What if you are on a production server and you need to suppress the errors?

In that case add the following the the top of your file, or include it as a header.

{code type=PHP}
ini_set(“display_errors”, 0);
ini_set(“log_errors”, 1);
{/code}

Optionally, if only a particular statement is throwing an error, you can do this:

{code type=PHP}

$myName = @get_name();

{/code}

The “@” symbol will suppress any errors that the calling function makes.

Remember, suppressing errors is no substitute for good coding.  But, sometimes you do what you have to do.

Author: Jack Slingerland

I'm a software engineer working and living in Raleigh, NC. I work in Python, Django, Node.js, React+Flux, AngularJS, and PHP. I like to work out with Kettlebells, run, and spend my free time with my wife, cat, and dog.