Is there a smart way to check whether output has already been sent to the browser and sending a header would generate a PHP_WARNING?
Obviously there's the alternative of using an output buffer, but that's not always an option.
Is there a smart way to check whether output has already been sent to the browser and sending a header would generate a PHP_WARNING?
Obviously there's the alternative of using an output buffer, but that's not always an option.
If all you want is to hide the warning, just turn off error reporting:
$old_er = error_reporting(0);
header(...)
error_reporting($old_er);
Or, you can redirect PHP errors and warnings to a log file (which is preferable in production, IMO).
You can use the headers_sent() method. This because before anything is outputted, the headers will be send first.
if (headers_sent())
{
trigger_error("Here you got your warning", E_WARNING);
}