Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107661 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32952 invoked from network); 24 Oct 2019 19:35:08 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 24 Oct 2019 19:35:08 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 1E0C22D1FA2 for ; Thu, 24 Oct 2019 10:21:35 -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=-0.6 required=5.0 tests=BAYES_05,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-xe41.google.com (mail-vs1-xe41.google.com [IPv6:2607:f8b0:4864:20::e41]) (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 10:21:31 -0700 (PDT) Received: by mail-vs1-xe41.google.com with SMTP id l5so5443675vsh.12 for ; Thu, 24 Oct 2019 10:21:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=NCwIMcfvPerP7uSrtFdplpvwPEAug9uUr7reQvb0ViU=; b=tjO/odUTb1YrQt6nW57mWbH36K8AzIHeEQCN2jF47acsa5G1KOyOb5gSHGp1MwDE3e 0Act5hQkDVab9l74Kkii0GAdOENS+ZFmzGGP8v4T/TGGGciakJbFVK4xAQsrb0wdB7D6 gSZ7SdSQJshbebO9yN0/PAyFCXVYstc/Mf5gVAPBZiSAYGPfOZR68bhnPk8TS5wpx03+ ezvV1xtzrDBrKXIXuVWRzITb5Q4MuYNc8c7etcSPYZAcD8KBLu5gsHotk1yyr7TLUC8+ RQFCCOKWRkJ3fklqdSA7ZNU61K0O2FyO36DdMirqL+OdaGyu0TR6AP0uPtCb2+WNFWPf OdzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=NCwIMcfvPerP7uSrtFdplpvwPEAug9uUr7reQvb0ViU=; b=S9efEOQKL+bE0+t7VRB0NuQ7+mJ8B0xURgppdrmSaXlPpBIhdhJI3WakDdkw6i2Vg/ bemDVj2pLZ9fKcedloRzWH9wBaIb2l5O0EeGrqKh4wk02eN6FFO+uAECI+c00N5MXsG4 VI9zOaeGDm2dkye10nnABl3e//E7dOwMTt55Od776PhPfCZF41gVIY52ZI8Shd8ufoYi dUX0PQdXbUOZfV9imeqjAr/8jJAar9LL7u3FRprkouVfy3nm4U0d6BVLGHDY+Y/8ZSlG VklmPV/87Dh6lC7kkoO2JTwT7vi3AqGsqNajUreFKCwllGT7b+NH8zP9KIdvA/1yHv4C Kp2w== X-Gm-Message-State: APjAAAWfTYlkezWMnaJZiTg8RUGos+pHUD3kS2dst9zK4jTxqDuYQGXz su9Zm7QjbdDLga1OthWuZlPVzTEf7IyBuY+nUa7wBTl4 X-Google-Smtp-Source: APXvYqz0JICcRzX4YuFovwM9eD8qcMMLQ63GqVolGs5FSg5cxY2QDxMNtJbgjawNzfpH+2H1yFp4mV9DEbK/m/qBzPY= X-Received: by 2002:a67:2c49:: with SMTP id s70mr9485525vss.167.1571937690671; Thu, 24 Oct 2019 10:21:30 -0700 (PDT) MIME-Version: 1.0 Date: Thu, 24 Oct 2019 13:21:19 -0400 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000a95f6c0595ab430e" X-Envelope-From: Subject: [RFC] anti-coalescing-operator From: dohpaz@gmail.com (Ken Stanley) --000000000000a95f6c0595ab430e Content-Type: text/plain; charset="UTF-8" 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? You're left with the traditional (and sometimes verbose) methods of using if conditions or the full-blown ternary operator `$foo !== null ? : null;`. I am here to gauge the interest of the community in having an anti-coalescing operator that would execute code only if the condition is not null, otherwise returning null in its stead. If this is not a wholly terrible idea, I will -- as suggested -- then continue to create an official RFC. My initial thought process would be to use a similar syntax to the Null Coalescing Operator (??), but to add negation: `$bar = $foo !?? $foo->getBar()`. I didn't want to use `!?` because then if anybody wanted to add an anti-ternary operator (e.g., `!?:`) for falsey comparison, then they'd have to get creative or use the three-character approach I am already proposing. The purpose is simply to negate the existing behavior, so at first glance I do not see any BC breakages or additional complexities that haven't already been addressed - naturally, I could be wrong. The driving use case, as hinted at in my above example, is if I have a nullable object I only want to call a method on it if the object is not null. Otherwise, default to the null value. I am working through the RFC Howto [https://wiki.php.net/rfc/howto], and it suggests that I ask for wiki karma for my account (897syudjhf) so that I may create the RFC when appropriate. Additionally, I have not [yet] found any existing precedence for anti-coalescing; i.e., there does not seem to be an elegant counterpart to COALESCE() in SQL. And, as they say, naming is hard. If `anti-coalescing-operator` does not sit well with you all, I am open to naming suggestions. Thank you for your time, Ken Stanley --000000000000a95f6c0595ab430e--