[php-src] Issue #8906: wish: config option to make undefined array key a notice again
| From: | RichardNeill | Date: | Fri, 01 Jul 2022 23:16:14 +0000 |
| Subject: | [php-src] Issue #8906: wish: config option to make undefined array key a notice again | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241847@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8906
Author: RichardNeill
### 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,