Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107691 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53347 invoked from network); 25 Oct 2019 11:49:15 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 25 Oct 2019 11:49:15 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 213FB2D1FF1 for ; Fri, 25 Oct 2019 02:35:52 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Fri, 25 Oct 2019 02:35:51 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id t5so1242899ilh.10 for ; Fri, 25 Oct 2019 02:35:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=fDXQGi6Xfp8EORYO/DzXdvbve0idMBn3xIxW/m/3pBU=; b=clykj4PTeoT5Q2Cs7UWIifrLkJnb7/4pM7CaH4Z9YeWOr65caYxJvWa993BSVsdtMH WrPRDfyeM32oQaBw8oqJL13fFElyBIsQIy7Pe8wzQGcj/ZLETPOIa33HCP+NZiHrtSs/ Q+H+GoQdA1+YTXKKUATfzNNwGzd9jJ0GXSzU0ZEmZgo7rQSfE+4ZYcyEw0k4LXo3194g jBcGjNliR3dSwIVq7VG4AqFuJ2TM5O93blqBj6tSq3/imdMwSJcOxIbKrlATXbJr9azC R9m5uTpAS7DGasy/zPuhJB8zad10xTo01IN92vXRveSow78BWhcy/4aAp22m29rBzY/L 6QHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=fDXQGi6Xfp8EORYO/DzXdvbve0idMBn3xIxW/m/3pBU=; b=ocPw0BvL4rZ1jrMAef6W08MFvfb7CC8xTIYO1TK9RZzWKRqgXC3/HmP8GyXkb2RaI7 GknF4W2zRFuSaA+SD9sjqkXZRsAzqis0fi1bXNuVr/8N6hmd+itwgUYh8KgwChB0YmSi uEokwfK54MXes1E7Bi74MWRjN98nPrBozcQizf6eK9khKgi0KZGYB4LUpG8k7n3BG9rq nslhKMyvi6gYGUyiIuXspSFvt98ueOV2I8QnLk2BoPgNOWzMwpLtkI9JiarmIlgNWuv2 wpcuuGjgAiXbL5KOaAGVPxTqFquAMyKpvaS1i5bR5Z6je5ZKNjP6f/jW8Ka31eAS1Die WqSQ== X-Gm-Message-State: APjAAAX1QLcgGCjOMkV3zGyVDz41oDSZiAea8TqXhvYncXXoEM7Le8vr N/qTWPrvXpWEOfZrTmBSR6DgBWfp0DYKjQ3JFkQyXhLZ X-Google-Smtp-Source: APXvYqyB0IDZceFrTT9/z5xLU4JUERjs1uw2QAbM/5R9YBiYdqSuJY2RNzHoYrRXrnhecHQNPmFERTFtU6ZV9K+iQY0= X-Received: by 2002:a92:7982:: with SMTP id u124mr3123532ilc.161.1571996150831; Fri, 25 Oct 2019 02:35:50 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 25 Oct 2019 10:35:39 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="00000000000028b4610595b8e067" X-Envelope-From: Subject: Re: [PHP-DEV] [RFC] anti-coalescing-operator From: rowan.collins@gmail.com (Rowan Tommins) --00000000000028b4610595b8e067 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 25 Oct 2019 at 03:37, Ken Stanley wrote: > This got rejected for being too large??? > If you trim the quotes in your replies to just the parts needed for context, it keeps the message shorter, and makes it much easier to read through. > > The fact that it=E2=80=99s a counterpart to an existing syntax l, I bel= ieve, > > further warrants it=E2=80=99s inclusion into the language. > As I mentioned before, it doesn't feel to me a very natural complement. The use cases for the new operator don't feel like "the negation" of the use cases for the existing ?? operator, and although different from null-safe calls, have more in common with them than "coalescing". > >> The repetition becomes more relevant if the expression we would repeat > >> is really long: > >> > >> isset($something['something']['something']['something']) !?? > >> $something['something']['something']['something']->foo(); > > > > > > This would be invalid because isset() returns Boolean I suspect that was just a mistake; the point was the new operator doesn't save any repetition in an expression such as: $something['something']['something']['something'] !?? $something['something']['something']['something']->foo(); Which in this particular case could be rewritten if we had a null-safe call operator, and would gain a lot more readability: $something['something']['something']['something']?->foo(); > > As far as flow control, let=E2=80=99s make no mistake, ??, ?:, and the = idea of > !?? > > are all succinct forms of flow control. To pretend otherwise is a bit > > naive. > I think you're misunderstanding what people mean by "flow control"; the key point is whether you're using the operator to obtain a value, or to trigger a side effect. For instance, this would not generally be considered "flow control": $x =3D $someFlag ? 1 : 2; Yes, strictly speaking, you're selecting one of two paths, but the only side-effect is an assignment, outside the expression. Compare to this, where the value of the expression is never even used, and you're just choosing a side-effect: $someFlag ? deleteUser() : logOut(); Your second example was better in this respect, because it used the result: $user =3D $application->getUser() !?? $this->getUser(); However, is this actually the desired code? If I'm not mistaken, it would de-sugar to this: if ( isset($application->getUser() ) { $user =3D $this->getUser(); } else { $user =3D null; } Given that your specified aim is to look up a default, isn't this actually a case for the existing null-coalesce operator? $user =3D $application->getUser() ?? $this->getUser(); // or if the precedence is the other way around: $user =3D $this->getUser() ?? $application->getUser(); Regards, --=20 Rowan Tommins [IMSoP] --00000000000028b4610595b8e067--