Share via:

Display_errors with Strict_types Gives 500 Error

How to fix a problem with strict_types causing internal server errors in PHP.


Edited: 2020-01-05 02:28

There is a problem in PHP 7 when using display_errors in combination with strict_types which causes a 500 internal server error. The problem likely happens because you are using an integer when setting display_errors.

To correctly turn on errors, place the following at the top of your script, before writing any other code:

<?php declare(strict_types=1);

opcache_invalidate(__FILE__, true);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');

See also: PHP Data Types

Why you are getting 500 errors

The problem happens because you are using an integer instead of a string when attempting to turn on errors from within a PHP script.

The ini_set function expects a string value, probably because it is modifying configuration file values. Normally PHP will not use strict type checking, and that is why it still works with an integer.

The below does not work as you would expect:


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


  1. Custom Error Handling in PHP