Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117147 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 83722 invoked from network); 26 Feb 2022 21:49:53 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 26 Feb 2022 21:49:53 -0000 To: internals@lists.php.net Date: Sat, 26 Feb 2022 23:10:27 +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> 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 array indexwarning when used ina ternary From: marandall@php.net (Mark Randall) Message-ID: On 26/02/2022 22:34, Robert Landers wrote: > This is not semantically the same though. A $_POST of a form, for example, > will usually contain an empty value if the form input was empty, but > missing if the form control wasn't in the form (maybe the form control is > injected via Javascript, or conditionally output by the script). PHP is a general purpose language, the behaviour you're asking for is specific to one use case and may be of detriment to others, without offering significant benefit in exchange. I suggest you write yourself a function that performs the operations for you. This may also be a good opportunity to move away from directly accessing the superglobals in userland code. $form->get('foo', 'defaultgoeshere'); Performance concerns would be so so small they would be practically undetectable in the context of a real request. Also, this: $name = empty($_POST['name'] ?? 'Default Name') ?: 'Default Name'; Should be: $name = ($_POST['name'] ?? null) ?: 'Default Name') -- Mark Randall