Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107695 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72281 invoked from network); 25 Oct 2019 12:40:43 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 25 Oct 2019 12:40:43 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 9A5302D1FAE for ; Fri, 25 Oct 2019 03:27:20 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) (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 03:27:20 -0700 (PDT) Received: by mail-qt1-x82f.google.com with SMTP id d17so2488212qto.3 for ; Fri, 25 Oct 2019 03:27:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wK6R5UwRBK8yKoX9sjVzl+6Rz5q6+WGhve9+wh25SKE=; b=EhGX3tK8zbzY7EimTHT6C1IJN+8HdzJnFUE5QWfTdOklQAo0/6lD/wm6lsJTCQB3eP 5/kT9PYLifY6L2/FukGWaTGEKn7zbgXH9iqKb3aQWSHmW454ZXxFGDh3eBrY91KtRy8R cpFxglZuJuZccmynqJsgbrDVgkjrjAKOmHBUKQqNCheQlfPp6PA5Hq37qmCwG+EHUJau A6BUcBjeuUUg9c0o7YZQtKB8+xQjPpQyZTKvmOaVCfRW2p1hFPwhVAnJjS+ivXcUykZs SQrENxx1OUMa/eotX947gUMG3Kym46527F/q8cw2aa6P+AKe5PK4WqrBx5zagAZySl3N oGcA== 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=wK6R5UwRBK8yKoX9sjVzl+6Rz5q6+WGhve9+wh25SKE=; b=ukI37oopQjhqYRCOV/VDMeNfqXzIEu39+BRi2KI5DPmZqcbcY6gdZUfzx7Xecy2FVx GWJFtENsfis3bM0rQKbzcpFm9fcKc+YVvLv7xDFbtpvEHJBr3HnFw/7dMAL+XBB1D40R yhGcbKSyRErGYOX+BknMXMNAM1J67O8/SmSYlHbF3r4vUbsYcHaUz2pS9cXvuztb4EJd OaINDHNqMoakKV1jTrLpcq1PYCxHgaSSLBfrg0wqogAFgX9p1swqJXsDoZp+wH7hLAJv I5iXHW+sEQyZLWwL/i3bjl6+wpFQt2C6XYrF5Drb2kr58rzYLlsey1zVMG9HFDLBeLam XbDQ== X-Gm-Message-State: APjAAAUkgnbfwfW7RbdEEF8k4IXHQKiHOawDWbenUbquWTPnAMUVvHQW 4PpMnKl6pA0NiRVOU+FiW4m944KSrPA= X-Google-Smtp-Source: APXvYqxsYqc5UI/Cexct5Bm/qzL/TYe4srNmmbP3uJj2REtDoTSulUURGIxBVnj4BkAQ3Df9En3gFg== X-Received: by 2002:a0c:ee26:: with SMTP id l6mr2474206qvs.71.1571999239140; Fri, 25 Oct 2019 03:27:19 -0700 (PDT) Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com. [209.85.222.175]) by smtp.googlemail.com with ESMTPSA id z72sm849645qka.115.2019.10.25.03.27.18 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Oct 2019 03:27:18 -0700 (PDT) Received: by mail-qk1-f175.google.com with SMTP id u184so1249448qkd.4 for ; Fri, 25 Oct 2019 03:27:18 -0700 (PDT) X-Received: by 2002:a37:a796:: with SMTP id q144mr2093052qke.494.1571999238164; Fri, 25 Oct 2019 03:27:18 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 25 Oct 2019 12:27:06 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Rowan Tommins Cc: PHP internals Content-Type: text/plain; charset="UTF-8" X-Envelope-From: Subject: Re: [PHP-DEV] [RFC] anti-coalescing-operator From: andreas@dqxtech.net (Andreas Hennings) On Fri, 25 Oct 2019 at 12:21, Rowan Tommins wrote: > > On Thu, 24 Oct 2019 at 22:20, Kosit Supanyo wrote: > > > But I think this functionality should be of something like pipeline > > operator: > > > > // send tmp variable to the next expression unconditionally > > $ret = $_SERVER['fname'] |> $user->setName($$); > > // send tmp variable to the next expression only when $_SERVER['fname'] is > > set. > > $ret = $_SERVER['fname'] ?|> $user->setName($$); > > > > Also the syntax like above will be consistent with the proposed > > safe-navigation operators. > > > > > I really like this idea, and it actually makes the pipeline operator itself > feel more useful, too. > > Imagine this chain, where not only might the variable not be set, but it > might not match a user, or the user might have no name: > > $upperCaseUserName = $_GET['user_id'] ?|> User::getById($$) ?-> getName() > ?|> strtoupper($$); > > As well as not needing to repeat the expression each time, as you would > with an "anti-coalesce", "null-safe chain" feels a clearer reading of the > intent here than "if not unset". I like this. It is a bit like a temporary local variable. One limitation is that you only have one such pipe value at a time. E.g. it would not cover this: return isset($a, $b) ? foo($a, $b) : null; or any nested parameters like foo(bar(baz())) where any intermediate value could be null.