Re: Proposal for RFC to remove undefined array index warning when used ina ternary

From: Date: Sat, 26 Feb 2022 16:35:33 +0000
Subject: Re: Proposal for RFC to remove undefined array index warning when used ina ternary
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-117143@lists.php.net to get a copy of this message
On 26/02/2022 09:09, Robert Landers wrote:
I'd like to propose and implement an RFC that would consider dropping the warning if and only if array access is the only test in ternary and short ternary (?:) operations but first I'd like to start a discussion to see if it is worth pursuing. I'd like to target PHP 8.2 or 8.3.
The warning comes from the array key being missing, not from being empty. There are many values which are empty which do not emit the warning. If you want to provide a default should the array key be missing you want null coalesce. $x = $array['foo'] ?? 'somethingelse';

« previous php.internals (#117143) next »