Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115951 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53246 invoked from network); 4 Sep 2021 22:19:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Sep 2021 22:19:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 750311804C8 for ; Sat, 4 Sep 2021 15:56:12 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,CTE_8BIT_MISMATCH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24971 185.25.184.0/22 X-Spam-Virus: No X-Envelope-From: Received: from vm1861.cust.netio.cz (micropro.cz [185.25.185.45]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 4 Sep 2021 15:56:11 -0700 (PDT) X-Virus-Scanned: amavisd-new at vm1861.cust.netio.cz Received: from [192.168.50.2] (ip-217-030-071-084.aim-net.cz [217.30.71.84]) by vm1861.cust.netio.cz (Postfix) with ESMTPSA id 20219A3C21; Sun, 5 Sep 2021 00:55:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=micropro.cz; s=default; t=1630796139; bh=JBWMgQK6+HGZyqbypwUM/CSq61TbAK+XUAcUAKzms0g=; h=Date:Subject:To:References:From:In-Reply-To; b=j/Hon43sRlxvHpAuX8Hr7Q8JjaaybzDLCuotPJkl6Wtq02VYC6PdpLti1f2q06q5P 4Jumylre5cCGuQBmw/t98H/9zm7RT0qdw2Vs4CaIxF75FRoiHf7bPnydLu68Z2GdIi X28Wt2+0OPIYeLjcBARQp1VfeIFHJO8b1ojGu0qs= Message-ID: Date: Sun, 5 Sep 2021 00:56:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Thunderbird/92.0 Content-Language: en-US To: Ben Ramsey , internals@lists.php.net References: <372fba7e-882f-7d34-9f2a-458de53eede9@micropro.cz> <20210904224243.53699A3C1C@vm1861.cust.netio.cz> Organization: Micropro Software In-Reply-To: <20210904224243.53699A3C1C@vm1861.cust.netio.cz> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: New operator suggestion From: admin@micropro.cz (=?UTF-8?Q?David_Kol=c3=a1=c5=99_-_Micropro_Software?=) Well, yes, but not exactly. What I dislike on ?? operator is, that it supress all warnings in the expression - in my opinion it shares the same issue as @ operator and why people discourage other to use it - because it may supress far more errors than you want to supress. And this is the case with $var->prop1->prop2 - when I expect just prop2 being undefined, it supresses even error of undefined $var, which might not be intentional and I miss that error because of that. So suggested ??: operator should behave like ??, but without the supression mechanic - just short hand for "$x === null ? $x : expr" instead of "isset($x) ? $x : expr". The 2nd case you wrote is actually even weird to me - I am not sure at all if PHP should behave like that. Because in your example, when $var is undefined: $var->prop1->prop2 ?? '' does not emit any error, because ?? supresses them $var?->prop1?->prop2 ?? '' does emit error - which is weird, since ?-> is still wrapped under ??, so I am not sure why error shows here. Anyway what I want is emitting error on undefined $var and undefined prop1, but NOT undefined prop2, when: $var->prop1?->prop2 ??: '' Do you get it? Just a shorthand for this: $var->prop1?->prop2 === null ? $var->prop1->prop2 : ''; Which any of suggested current solutions can't do. David On 05.09.2021 0:42, Ben Ramsey wrote: > David Kolář wrote on 9/4/21 17:19: >> Back to the suggestion - I suggest creating a new IFNULL operator, which >> will simply test if >> expression is null. If not, it returns left-hand part, if yes, it >> returns right-hand part. > This is already what the `??` operator does. For example: > https://3v4l.org/RlDjK > > Are you suggesting that it should emit a warning if `$var` is undefined, > as it does in this case? https://3v4l.org/aZAj0 > > Cheers, > Ben >