Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117151 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 12157 invoked from network); 27 Feb 2022 10:14:59 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 27 Feb 2022 10:14:59 -0000 To: internals@lists.php.net Date: Sun, 27 Feb 2022 11:35:41 +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: <621a56dd.1c69fb81.67b1.242aSMTPIN_ADDED_MISSING@mx.google.com> <621ab36a.1c69fb81.b1a5.462dSMTPIN_ADDED_MISSING@mx.google.com> 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: [PHP-DEV] Re: Proposal for RFC to remove undefined arrayindexwarning when used ina ternary From: marandall@php.net (Mark Randall) Message-ID: On 27/02/2022 09:12, Robert Landers wrote: > I'd also venture that this warning has caused more harm than good, in that > writing "$var['something'] ?? null" is second nature when writing new > code, even if there is practically no chance for a non-existent key. Using null coalesce should only be used when you know you have the possibility of a missing key. For everything else you've probably entered an unexpected state and should display a warning (that should ideally be picked up by an exception handler and convert it to an exception). When handling external data it is usually a good idea to use a validation step before using it, such as JSON schema. An even better idea is to parse it into a specific type, rather than just validating it, at which point you're going to be using a lot of isset, null coalesces, array_key_exists, property_exists etc anyway and sucking in some default other than null is almost always the wrong thing to do. As to your final point: PHP internals voted by a supermajority to raise this from a notice to a warning in PHP 8, it seems unlikely that 33% of people are now going to change their mind and vote for the opposite.