You are here:Home»KB»Programming»PHP»Disable and re-enable PHP error reporting within a function
Tuesday, 12 December 2017 12:04

Disable and re-enable PHP error reporting within a function

Written by

This is useful when you want to control the errors outputted tot he screen or is a class or some other code is not behaving as expected, such as the ADOdb error class.

The following code will preserve the current error reporting level so once your code has finished running the system's error reporting will be returned to its normal state.

// Get current PHP error reporting level
$reporting_level = error_reporting();

// Disable PHP error reporting (works globally)
error_reporting(0);

// Add you code here

// Re-Enable PHP error reporting
error_reporting($reporting_level);

 

Read 791 times Last modified on Tuesday, 12 December 2017 12:09