Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
error_reporting
communitycreator

How to turn off error reporting in PHP

Chinweuba Elijah Azubuike

Overview

It is quite normal for our code to have minor errors. Although such errors do not affect the execution of our code, PHP still displays them. A lot of times, this distorts the design of our websites. In this shot, we'll see how to turn error reporting off in PHP.

Reasons to turn error reporting off

  1. If the code is in production already, it may be unreasonable for end-users to see errors on the website.
  2. Normally, error reporting reveals details about the code, which may make it vulnerable to hackers in the long run.

How to turn off error reporting in our code

To successfully turn off error reporting in PHP, we use the error_reporting() function.

Example

<?php
error_reporting(0);
trigger_error("user warning!", E_USER_WARNING);
echo 'no errors';

?>
Turning off error reporing in PHP

Explanation

  • Line 2: We use error_reporting(0) to turn off all error reporting in our code
  • Line 3: We trigger an error using trigger_error(“user warning!”, E_USER_WARNING). However, because we have used error_reporting(0), the error isn't reported.
  • Line 4: We display our message without an error.

RELATED TAGS

php
error_reporting
communitycreator

CONTRIBUTOR

Chinweuba Elijah Azubuike
RELATED COURSES

View all Courses

Keep Exploring