Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107665 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 61357 invoked from network); 24 Oct 2019 21:12:56 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 24 Oct 2019 21:12:56 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 34DFD2C16A5 for ; Thu, 24 Oct 2019 11:59:24 -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-vs1-xe31.google.com (mail-vs1-xe31.google.com [IPv6:2607:f8b0:4864:20::e31]) (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 ; Thu, 24 Oct 2019 11:59:23 -0700 (PDT) Received: by mail-vs1-xe31.google.com with SMTP id v10so16948703vsc.7 for ; Thu, 24 Oct 2019 11:59:23 -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 :cc; bh=MtvROLZkK1KQYTHEDlAjbn5CINIFuvoEg7qL+Xik7dQ=; b=KdKvCWHSqqv4ouTSHQSLtuxXJoK/+Hj0Ut+BKTe5w1KjtRXoQjaAdZnlWxHXewPiT1 BbEL/cfByOgVagFEK9FUYqLGVSDez/aNrNKFypcqWUrnLJX73GL1lYz72RVoocnCNsB8 +Db8iQtRfJhxOB7dxO4x4mK2fum18MsuTL4MhmJDwZO+MTPE9c8Y+Dxlfvco5XglmorG VaAmZvXzrxxx9KFMDBmOGn5KanL1PCL2E67zHKiXsrfc1pLYO+EjM730u7oHQzU2pGu7 sUro31T3i8JQbZj1qjAd1nhAN3Ou4+A8g/J/GZ5AfDuhYxH5n+Au5uXq2nFz+ftu5UIk 75OA== 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:cc; bh=MtvROLZkK1KQYTHEDlAjbn5CINIFuvoEg7qL+Xik7dQ=; b=dyuNDOQjFGPMcrdxUjYOQ0irklIYpXDN4zIouKmc/Leyy4fnY4lrX4JaPHlATAjhMh bACijzXuO5w0Sm9ayy9TGHwO30TOj8wrGluOIlwtFyVNCuuFE5M8uRjM2lhTvW8qJie1 shKXSIVzqYOypPn/L3scHhnxoRbHoNK5/0TR75OswZ7Fo1uUmwVSrXu7QTvyi24uNI0c yEJ9n+mb9Yx7NHnghlTQr0/Lqp5YjCzKzAX7VmvTJuTeijsRd07IJ0Rmo+hOIwFXKH9V QTxjDcToHUCosfunNLQJxjyJ9zKJ6hszMWiH0qGvG6p8Sdnp0I3y3gnbDkHiNBadUODh g43A== X-Gm-Message-State: APjAAAVWBQwYafUwEZBILvWuPDDt3S2cFXVcdRXEpVqTbcRWQPq98Ujo Mh4nM5FOkQGeUE/XFZGAOPpqCwqKmIr7yakStKwbVPOQ X-Google-Smtp-Source: APXvYqyc8pOCbndHADxTK8fV0V5Tm/vZpocrraDEGdN8lmiEGM/2Z8UQ2aupQfXEEuV8xDgVqr+VV6DcWBRkVKboDGo= X-Received: by 2002:a67:fb92:: with SMTP id n18mr10025209vsr.187.1571943563226; Thu, 24 Oct 2019 11:59:23 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 24 Oct 2019 14:59:12 -0400 Message-ID: To: Dan Ackroyd Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000b172090595aca1ef" X-Envelope-From: Subject: Re: [PHP-DEV] [RFC] anti-coalescing-operator From: dohpaz@gmail.com (Ken Stanley) --000000000000b172090595aca1ef Content-Type: text/plain; charset="UTF-8" On Thu, Oct 24, 2019 at 1:33 PM Dan Ackroyd wrote: > On Thu, 24 Oct 2019 at 18:21, Ken Stanley wrote: > > > > Since PHP 7.0 brought forward the Null Coalescing Operator (??), writing > > more succinct code for how to handle null values has been a blessing. > But, > > what about the inverse when you want to do something when a value is not > > null? > > Hi Ken, > > It may help to give a real world example, rather than a metasyntactic > one, as I can't immediately see how this would be useful. > > People have been expressing a concern over 'symbol soup' for similar > ideas. The null colalesce scenario happens frequently enough, that it > seemed to overcome the hurdle needed for acceptance. Again, giving a > real world example of what you currently need to do frequently might > help other people understand the need. > > cheers > Dan > Hi Dan, After some thought, and searching through my existing code bases, I believe I've come up with a decent code example to help demonstrate the usefulness of the proposed anti-coalescing-operator: Without !??: getUser($userId); if (isset($_SERVER['fname']) { $user->setName($_SERVER['fname']); } if (isset($_SERVER['lname']) { $user->setName($_SERVER['lname']); } if (isset($_SERVER['mname']) { $user->setName($_SERVER['mname']); } if (isset($_SERVER['phone']) { $user->setName($_SERVER['phone']); } if (isset($_SERVER['email']) { $user->setName($_SERVER['email']); } $this-saveUser($user); } } With !??: getUser($userId); $_SERVER['fname'] !?? $user->setName($_SERVER['fname']); $_SERVER['lname'] !?? $user->setName($_SERVER['lname']); $_SERVER['mname'] !?? $user->setName($_SERVER['mname']); $_SERVER['phone'] !?? $user->setName($_SERVER['phone']); $_SERVER['email'] !?? $user->setName($_SERVER['email']); $this-saveUser($user); } } Thank you, Ken Stanley --000000000000b172090595aca1ef--