Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107696 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74013 invoked from network); 25 Oct 2019 12:42:25 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 25 Oct 2019 12:42:25 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id BE74A2D1FE9 for ; Fri, 25 Oct 2019 03:29:02 -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,URIBL_BLOCKED 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-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) (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:29:02 -0700 (PDT) Received: by mail-qk1-x72f.google.com with SMTP id u184so1253144qkd.4 for ; Fri, 25 Oct 2019 03:29:02 -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=+AUfM3P+GiccCMg2qBaS1XXI0eo6kR4w/me3AxPn0yA=; b=r20MuldykuGGZ+lBCa5Q89QsKTwbFZlJJL+1X5/fS5wdYZcYdyILeigRbPH0PAMV1i DarexovXTpg4ptfKP19EzMzwjtkjhu9PsHC+s6L+63qmkadvM4au3Qe2Lznh3nLtN1Gw daBHDi1JOz2LHIulPsotUyubQwbD9rkl9bqAExjxf5skaTAcu1JFEYRfXf9WjT75RAwa 8ixZd1ogZWo0cBdseInkUNbK/19nkV2xCmnsdGij3bG6R8zsDg/UTUoQSR+5H1fFtUeb z5jBku/m9s11UcGcVNDgLwQUyUfZHo3gf8phoLZbZvIR5pNgqwlpaJITCvPgrUUjuknE oLYg== 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=+AUfM3P+GiccCMg2qBaS1XXI0eo6kR4w/me3AxPn0yA=; b=oHLuYLdEL64aVP5DvxDRrr6cCs+vV7vlYe0HlsP1ho8RwYexqM8q8xKl10DOpYa0eE NOxkAO0pGE9sTtbt0wlF13jAzC23G1R6PqD9PcJgu4bN2dmELBx+uZb/DH19KwsiFIag H/CkrIo+zbVzh0tz7pbLNVGzrkegn+oDwD8HTqK8m2Kh1eaKKVN1nBYgiuvVnG6XE5pj R9nlz9K5ZSNduO82mpXVZgGeI5vOwG3N4fQVankDeSljvorFRP1p/T2LPwmzHPXtQdxi SOczGP/Nyikb0ofspqheHLWLxfMC3GNaac1JYsYSy06A6eqdDE6WiqOwWFiSewaw+Yuo m5SA== X-Gm-Message-State: APjAAAUv2T4PfV+ewnm0buBEpcGpwMB8oYRXuMmLosILWbgl6qbbq7mC t2UUyOZ63jTTxDVbrEgZsrh9LhwEqG4= X-Google-Smtp-Source: APXvYqyINyfJZ46NVWV+gTTlwas96m48FRdYY796BHt413NTe9pmhPWWGqfoH/e8+RuxSQqUOPFlDw== X-Received: by 2002:a37:4ed1:: with SMTP id c200mr2032794qkb.304.1571999341784; Fri, 25 Oct 2019 03:29:01 -0700 (PDT) Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com. [209.85.160.173]) by smtp.googlemail.com with ESMTPSA id a9sm891949qkb.94.2019.10.25.03.29.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Oct 2019 03:29:01 -0700 (PDT) Received: by mail-qt1-f173.google.com with SMTP id t8so2466123qtc.6 for ; Fri, 25 Oct 2019 03:29:01 -0700 (PDT) X-Received: by 2002:ac8:2d2d:: with SMTP id n42mr2189321qta.119.1571999340862; Fri, 25 Oct 2019 03:29:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 25 Oct 2019 12:28:49 +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:27, Andreas Hennings wrote: > > 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. Sorry, this last part is wrong of course. The pipe works great for nested calls. Just with multiple parameters which all can be null it does not.