Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99619 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18297 invoked from network); 22 Jun 2017 21:10:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Jun 2017 21:10:27 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.177 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.223.177 mail-io0-f177.google.com Received: from [209.85.223.177] ([209.85.223.177:36826] helo=mail-io0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 87/47-52620-2423C495 for ; Thu, 22 Jun 2017 17:10:26 -0400 Received: by mail-io0-f177.google.com with SMTP id j24so3053789ioi.3 for ; Thu, 22 Jun 2017 14:10:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=zBPZs7FGYp5MlYSmfSznggK/mJIV3tRMD4GzNOM3tOg=; b=dtrpBTgO49fPYxdoXcyvYGZsQuM6ihKG41a3QJ9YsAyYj23BnL3APtrZFKzwm/0pr/ /kEC8N1ZfQn2PkdlpH39dkYsymgoHL1powMPLDwKlAamFYH666Tp2fkdzTb/56rcQWKR Dge32d/ozBRKo9cvN6jP2MUpTJFz2Um1Ta0bouA3T6ujp2FU8xyWa0OJ4LeFUmF4LeXG W7bnUaox9FagWglgdL2HVA+L+2HOEOy7UzcAWSQR3S6M+ysbgh+W+4M6WyzVzR04NQt0 Q7h4zqp9INU729eQ6nf4C3mmMBuZV96tAQ8yAPzF/OJL3PLBdAVbTGr5rzGDwz7tW95s /F4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=zBPZs7FGYp5MlYSmfSznggK/mJIV3tRMD4GzNOM3tOg=; b=r0/f0RJFCUB+DLhgYhsbFJBBoJfna/LOR5FXcM+8QwooIRqhvzyCqZT3m27HQ9uSwz vOOkgWUR6tq/1rLyUBp3kdw8E8Mojxm11Z1Qxq/oE+PPySdYooNibk4fK4Ah/8BBnSfA sMZeOqB/r4HXOsgDNfIPMCFboehLlRhrSwGynwYSso+X0I6c6ZtOnceCQZziL3yorlMV xa2OWyYmXZVgb0OHTZBo6HK+XmhSHaDXjR4SRAjr0pch0ORQMZ3b4Xuze9VBeEAXv/Vz snf+fl/VqZ86cY+tTn7xOUtUMdG3iGY0nmRLN2EufW/gmRiuc74jq1Ed30cTDNEi7gSN z5Bg== X-Gm-Message-State: AKS2vOzXdlMnJ7rUywRyiGYrlFbnWeYF+DpdbY19D0BF1EBBBRTfSSL2 IX6NIsv2Sfh4CyiRG/euWp9pnyYzXg== X-Received: by 10.107.12.144 with SMTP id 16mr4240286iom.150.1498165823339; Thu, 22 Jun 2017 14:10:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.33.134 with HTTP; Thu, 22 Jun 2017 14:10:22 -0700 (PDT) In-Reply-To: <13.F6.52620.31E2C495@pb1.pair.com> References: <27.FD.13828.277AA495@pb1.pair.com> <098eb964-4187-f71a-f076-02fae9b042c6@gmail.com> <13.F6.52620.31E2C495@pb1.pair.com> Date: Thu, 22 Jun 2017 23:10:22 +0200 Message-ID: To: Andrea Faulds Cc: PHP internals Content-Type: multipart/alternative; boundary="001a113ee16ab707f3055292e9cd" Subject: Re: [PHP-DEV] [RFC] Unary null coalescing operator From: nikita.ppv@gmail.com (Nikita Popov) --001a113ee16ab707f3055292e9cd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jun 22, 2017 at 10:52 PM, Andrea Faulds wrote: > Hi Stas, > > Stanislav Malyshev wrote: > >> Hi! >> >> I think that `if ($_GET['x']?? =3D=3D=3D 1)` looks and feels a lot like= `if >>> (@$_GET['x'] =3D=3D=3D 1)`... >>> >>> Yes, the latter has runtime performance issues and will still send >>> notices to error handlers and logs. But perhaps if we're going to >>> extend syntax, the syntax could be something along the lines of: >>> >> >> I'd rather fix @ (or make another operator like @@ that Sara proposed) >> to make nullsafe access - and maybe even extend it to full expression >> like isset/empty does - so I could do something like >> @$foo['bar']->blah->foo['bah'] and have it mean "try to fetch the whole >> chain and if something is missing on the way return null". I kinda get >> the argument for PHP not doing it by default, though I personally could >> live with that too ;) - but I still need this thing quite frequently >> when dealing with all kinds of dirty data. >> > > You already can use @. I'm not sure how it could be "fixed": the > fundamental problem with @ is that it is a blunt-force instrument that > mutes all errors, but this is also its purpose, and any change to that wi= ll > break some use cases. The best fix would be to get rid of it entirely, bu= t > we can't do that since it actually has to be used in some cases right now= , > in particular standard library functions that produce E_WARNINGs on I/O > errors. > > With trailing ?? it is not clear how it would chain, >> > > It's a unary operator, I don't know what =E2=80=9Cchain=E2=80=9D would me= an for one. You > can use it within other expressions (1 + $a?? is valid, for example), and > you can nest it within itself ($a???? is also valid, though I've no idea > why you'd do that). > > and even if it >> chains having something at the end that changes how the expression is >> interpreted is both confusing and may be very hard for the parser. >> > > Unary ?? is a two-line addition to the syntax and completely unambiguous > from a parsing perspective. > As has been pointed out on reddit, unary ?? is ambiguous for cases like $a?? - 1, which could be either ($a??) - 1 or $a ?? (-1). Of course, precedence resolution is possible, but I wouldn't call the syntax unambiguous. Nikita --001a113ee16ab707f3055292e9cd--