Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117144 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 78705 invoked from network); 26 Feb 2022 21:13:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Feb 2022 21:13:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1BB511804AC for ; Sat, 26 Feb 2022 14:34:21 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 26 Feb 2022 14:34:20 -0800 (PST) Received: by mail-pl1-f174.google.com with SMTP id bd1so7664291plb.13 for ; Sat, 26 Feb 2022 14:34:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TMpMPlyXM3CwgiKQRTE8WFdH6D154+6VemV+dDjD904=; b=kVmORpbR+tOSTsZApthkf73tPhvb9lFSPRF3zzLbPSeediXvBSB4SzeoUk7FDkNolg tqoHhLZy+Rmll89V08YyGSengA2bMzScRv8G4ld7mHM76Po+D7MfMnk1rpFMjWC3sa4m rDD5Mt55oNObd3xFblLJ32nSdCh3gRe1bdBHdgQDYE9MxpbSuhfM4iGrsYzUQAoSUUrF fe+B3iuQXoJIvpW27jWj1R7bCh4RlyR7KvKrlQGkuuS4CqYinEQpKokRNDmrrjd1QJvw AO2FLyjvaXe+C9+axiEkf/MZizxwhL4QAclxRQ3jdcBhZii4/ORt6qdDTRpnMTpOD606 mfgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TMpMPlyXM3CwgiKQRTE8WFdH6D154+6VemV+dDjD904=; b=UuupXTARtTaJ+6mdITUm5Qfg1ONfOkpI1K1MHTjTRgyp7OHvDdvrrpL8t1ygaLnVJi ZVKyGfeeigAqxfHmsa88WakaS6F95cns2un0NecZ2L8B6DxUrh0YdV2FzeJfskl+rNav Iafn5oqF1BG1Dg4S55JNL6iXF+CAA82x37gCtwcAIbmE3iBQMtMuw5WFACvioqWpMNd5 P/SmZ73yi5OGuwZVZSU0GBWMnQg0mHg8kheA3qWIIpFfxEfsjY9PWidZTKDQz+CamdUt vs0hqv7ulZ/HodY2LTK8GR7/CVqaLxOZGgUZNw8D498gCuBf5eQ0Hz0D3RMhKRLwQ8ML Grlw== X-Gm-Message-State: AOAM532p6UHHU0egjv4Bu6KUBejfPIz4Gu6TAbRyFzpeow4Pgtv605Mx //TTMosqRn7GYh7UZxcRhwfiwMqmiRjnVABFeUwKA2juO1bDzqf6 X-Google-Smtp-Source: ABdhPJyjPkHAOqX02ezVzR8DCSC3tU8MTctJ4JP0F2lSU9LMwChv4n6tV2gIaQ9Zk3MWB7asX+nzuThAclqQUfaNVho= X-Received: by 2002:a17:902:eb90:b0:150:e0a:c222 with SMTP id q16-20020a170902eb9000b001500e0ac222mr13561881plg.111.1645914859194; Sat, 26 Feb 2022 14:34:19 -0800 (PST) MIME-Version: 1.0 References: <621a56dd.1c69fb81.67b1.242aSMTPIN_ADDED_MISSING@mx.google.com> In-Reply-To: <621a56dd.1c69fb81.67b1.242aSMTPIN_ADDED_MISSING@mx.google.com> Date: Sat, 26 Feb 2022 23:34:08 +0100 Message-ID: To: Mark Randall Cc: internals Content-Type: multipart/alternative; boundary="000000000000834c6405d8f36a7a" Subject: Re: [PHP-DEV] Re: Proposal for RFC to remove undefined array index warning when used ina ternary From: landers.robert@gmail.com (Robert Landers) --000000000000834c6405d8f36a7a Content-Type: text/plain; charset="UTF-8" On Sat, Feb 26, 2022 at 5:35 PM Mark Randall wrote: > 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'; > > 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). Here is how the code might look currently to handle a default value for an empty form post that may or may not be sent in the request (ignoring how insecure this looks): $name = $_POST['name'] ?: 'Default Name'; Semantically the same to get rid of the warning: $name = empty($_POST['name']) ? 'Default Name' : $_POST['name']; I'm not sure your suggestion to set a default applies since we have to do the empty check anyway, which swallows the warning? $name = empty($_POST['name'] ?? 'Default Name') ?: 'Default Name'; > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > Robert Landers Software Engineer Utrecht NL --000000000000834c6405d8f36a7a--