Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110402 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40171 invoked from network); 6 Jun 2020 18:34:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jun 2020 18:34:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0C47B1804CE for ; Sat, 6 Jun 2020 10:17:11 -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=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (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, 6 Jun 2020 10:17:10 -0700 (PDT) Received: by mail-yb1-f181.google.com with SMTP id t9so6651380ybk.9 for ; Sat, 06 Jun 2020 10:17:10 -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; bh=bqnBBefFRPv8ehAkQZEq44RF1SCZTgsZza14RXyBQKc=; b=PGpNxbtBY3T/1Q2Iq6ygeVlb9RHpbb1QF2aPhjsuAssNiuHgKaHOF8k1iApwp4kSCm 8U0g/Yt4ZfzMpPZLZKgIu6y45hJz9mzCNFm4am3jWBNoZhsA8rEJ1WhOIv61AB7TWvby E9mkST4tJGk9jl93rPhfXY9wyfE6dY+wj2GNo3XjqoWZ+1H2/uOeslPodbe1j8Bf2mc5 kUjLSnGinojzulpaYINOpeGd1YhDF6mCqeI4HaIWK3IhOGD/V+81a5nZewMvfGlX13OT MWCD36yoOjXw0kW+2BGBEPHrgJ+7uBFoFSofOKX7SwhTlNTLNOSEVQFQYtNxoDUE7MQS 46rg== 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; bh=bqnBBefFRPv8ehAkQZEq44RF1SCZTgsZza14RXyBQKc=; b=EJG/47sgDxnT5895cFiwz3Cf3BDDtORmSJ0Elo3qnQVJ3wSuw2zZMym3Y6PvlKdjsP YNAX393hEN+GQWv0EnGHflYMzaZl1QfsrHi1ozUMrUS2ZrJFKvYsbAWbfEKoVSMCWr+Z iPaG78WWCt3Ve8P5lOwXV0g5ka/c5GyLIMv0gV7lIV5bOnpUiUWAYEhvVE89QGqLc+U0 BdJN38FtgfD1TiJz9P9UXbczLJiB1yoOZ9k02ldDs8MhIYbBva6hVtiyHu7dnXICSwS3 byLeDsCV7fdp+tEY5X8FWIoUQNL8Rh98cXilIIFfx1hyzu3Me2sRobeFP0I/D+zTNgLM AK8Q== X-Gm-Message-State: AOAM530vj1emod8ofkw4r13HOb26jMI87cC/S7scLFi9ZA4I73QkLCmb 1VQv3dmLBTg/qsHS8Gq1chJxovq3HD8IbzefBV+cODJn X-Google-Smtp-Source: ABdhPJwMBjwrnm0XcXqcIUtk0vU7ILRNIdNPJ7FrZN7Kvxm7p6JITvF/ZqTJoQCX0OwyWI8TOnprh7uS/Xg2z3dfsqg= X-Received: by 2002:a25:af06:: with SMTP id a6mr27230538ybh.109.1591463828856; Sat, 06 Jun 2020 10:17:08 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 6 Jun 2020 19:16:57 +0200 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Nullsafe operator From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Peter > Wouldn't it make more sense to make `isset` smarter? So that it can > handle these situations just like it would with array access. That > way you could use the null coalescing operator as well. Both of those are valid approaches. I do prefer the ?-> operator for two reasons. 1. ?? is more error prone (e.g. you won't get an error if a variable or property is undefined) 2. You can see immediately which sub-expressions can be null and which cannot (or rather must not) That is not to say that there aren't also benefits to ?? 1. No new syntax to learn 2. You can see more clearly where the short circuiting chain ends > I don't see many situations where you would be selective in which > method in the chain you would want to make nullsafe and which ones you > wouldn't. IMO you should only use ?-> exactly where you expect null values. Using ?? would ignore null (as well as undefined) everywhere in any sub-expression even if unexpected. > I don't recall ever having to nest three levels like that example. I agree. Take the example with a grain of salt. It's hard to come up with a relatable, meaningful, short example. > Sorry if I come off a bit harsh, but I don't see the need for this as > other solutions to this problem are more favourable IMHO. Not in the slightest. That's why it's called a "request for feedback" and not "request for praise", you're free to disagree :) > As much as it can be annoying sometimes, the `Call to a member > function foo() on null` is a very useful error. Absolutely. To clarify: The idea is not to sprinkle ?-> everywhere. Only use ?-> when null is an expected and acceptable value. Ilija