-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
Description
In PHP 7, underfined array keys created E_NOTICE. This is now E_WARNING.
Can we please have a configuration option to put that back to E_NOTICE?
Rightly or wrongly, there are a lot of people, myself included, who have thousands of lines of code with things such as:
if ($_GET['xxx'])
#where xxx may or may not exist.
or
if ($_GET['xxx'] == 'yyy')
and in PHP8, we now get flooded with warnings "Undefined array key", which get in the way of real warnings.
Migrating and testing this code will take a long time, and furthermore, it's really ugly and harder to read:
if (isset($_GET['xxx'))
or
if (isset($_GET['xxx']) && $_GET['xxx'] == 'yyy'))
to suppress this warning.
Instead, it would be better to have some sort of pragma in the main header
ini_set("array_key_missing_enotice", true);
ini_set ("error_reporting", E_ALL & ~E_NOTICE);
To me, it seems sensible that a defined associative array, with a key that isn't present (and may not be expected), should not be a warning, especially if it's being tested for with if().
It may also be worth treating undefined variables the same way.
Thanks for your help,