-1

I have XAMPP 5.6.3 on my development environment. I have a problem that my development environment is too tolerant. The problem is that if I run this on my development environment

echo "1";
header("Location: /homepage.php");

it will redirect to homepage without problem.
But if I do the same on my production environment, it would give the common error of (Cannot modify header information).

What I want is to receive the same fatal error on my development environment.

Thanks in advance!

Aproram
  • 348
  • 1
  • 3
  • 16

1 Answers1

0

You need to turn on error reporting to receive the error. You can do it from code or by modifying php.ini

From code

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Or find php.ini file in xampp/php directory and modify these line

display_errors=On
error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT

You can choose any other Error Level Constant You can also check this answer How do I get PHP errors to display?

Edit: You can use set_error_handler function to modify default error behavior. Here is the documentation for this function https://www.php.net/manual/en/function.set-error-handler.php Here is a example code to make warning fatal

function myErrorHandler($errno, $errstr, $errfile, $errline)
{
    if (!(error_reporting() & $errno)) {
        // This error code is not included in error_reporting, so let it fall
        // through to the standard PHP error handler
        return false;
    }

    switch ($errno) {
        case E_WARNING: 
        case E_USER_ERROR:
            echo "<b>My ERROR</b> [$errno] $errstr<br />\n";
            echo "  Fatal error on line $errline in file $errfile";
            echo ", PHP ".PHP_VERSION." (".PHP_OS.")<br />\n";
            echo "Aborting...<br />\n";
            exit(1);
            break;

        case E_USER_WARNING:
            echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
            break;

        case E_USER_NOTICE:
            echo "<b>My NOTICE</b> [$errno] $errstr<br />\n";
            break;

        default:
            echo "Unknown error type: [$errno] $errstr<br />\n";
            break;
    }

    /* Don't execute PHP internal error handler */
    return true;
}
error_reporting(E_ALL);
set_error_handler("myErrorHandler");
  • Doesn't work, these are actually the default values at my php.ini . It's about considering that as fatal error more than reporting the errors. It's already reporting errors. – Aproram Sep 23 '19 at 23:00