<?php
/**
* Suppresses errors for specific text blocks during development.
*
* This function wraps code blocks with error suppression for debugging purposes.
* It should be used cautiously and removed before deploying to production.
*
* @param string $startTag The opening tag for the error suppression block.
* @param string $endTag The closing tag for the error suppression block.
*/
function suppressErrors(string $startTag, string $endTag): void
{
error_reporting(E_ALL); // Report all errors initially
ini_set('display_errors', 1); // Display errors
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT); // Suppress specific error types
ob_start(); // Start output buffering
$code = $_SERVER['REQUEST_URI']; // Get the current request URI
if (strpos($code, $startTag) !== false) {
// If the start tag is found, suppress errors
error_reporting(0); // Turn off error reporting
ini_set('display_errors', 0); // Don't display errors
}
ob_end_flush(); // Flush the output buffer
}
/**
* Example usage:
*
* Wrap code blocks with the suppressErrors function to disable error reporting.
* Example:
* <suppressErrors><code class="php">
* <?php
* // Code that might generate errors
* $variable = null;
* echo $variable->someMethod();
* ?>
* </suppressErrors>
*/
?>
Add your comment