Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117143 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 66460 invoked from network); 26 Feb 2022 15:15:03 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 26 Feb 2022 15:15:03 -0000 To: internals@lists.php.net Date: Sat, 26 Feb 2022 16:35:33 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Content-Language: en-GB References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 87.81.129.66 Subject: Re: Proposal for RFC to remove undefined array index warning when used ina ternary From: marandall@php.net (Mark Randall) Message-ID: 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';