Categories
PHP Programming

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.

By Jack Slingerland

Founder of Kernl.us. Working and living in Raleigh, NC. I manage a team of software engineers and work in Python, Django, TypeScript, Node.js, React+Redux, Angular, and PHP. I enjoy hanging out with my wife and son, lifting weights, and advancing Kernl.us in my free time.