'Upgrading from PHP7.4 => PHP8, is it possible to ignore certain errors

We have a huge codebase where we ignored the notice from php7 when accessing undefined variables or array-keys. For example

$somethingThatMayNotExist = $_REQUEST['somethingThatMayNotExist']

PHP8 now throws an Error. I know that we should always check if the key exists, or if the variable is defined. But the codebase is so big and we have poor unit-test coverage that I would rather switch to php8 and have these errors handled as notices (And setting the value to null). Is this with somekind of custom error-handler possible? If so, how to do that?



Solution 1:[1]

I used this regex find and replace:

$_REQUEST[(.+)]

($_REQUEST[$1] ?? "")

Without the outer parenthesis in the replace, the html got messed up in places.

I used Regexxer from the Linux Mint Software Manager to replace in the multiple files. The regex find and replace in Notepadqq doesn't work properly.

Solution 2:[2]

php8 create exception on non isset array keys. and you may be create global hook for proccessing this exeptions.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AndrewT
Solution 2 LLIypLLIuk