Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112175 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50047 invoked from network); 3 Nov 2020 21:49:26 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Nov 2020 21:49:26 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A7AB51804D1 for ; Tue, 3 Nov 2020 13:09:52 -0800 (PST) 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.1 required=5.0 tests=BAYES_00,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-Virus: No X-Envelope-From: Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (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 ; Tue, 3 Nov 2020 13:09:49 -0800 (PST) Received: by mail-yb1-f182.google.com with SMTP id c18so3254557ybj.10 for ; Tue, 03 Nov 2020 13:09:49 -0800 (PST) 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=zXMUGHrVO2RyspFoRCi64LS7ltWbQ6WsPrrwMuR7B9k=; b=ghGiB7YKntyZFe5A2KzQvAX4OREd4AULM53/81wbtfkZvFYkcC2Npi3jaoP3523H2Z 5uCno2vloL52zMvA01hat2zSQPgwfQ1DE2QKpBZVAHyWX7+w8idot/kusOZSgxniYygz WN3vBZUT5GVVtlodO4YzqdMIQ7WDL6uCo/0oRJxq89L4/3H64LEKWpWgMcUdDMuZIY+r Lgpuy41ZCxNgvXFDqOGUjH4g2TRLKTZqnQ3ttY/CAxKAENauhWuHmZxzIIZ3DyExt0Tn U+xMMq96x09EEaop1aLe2EZc7RbD1laa5eOK6soyxtNC0w7fW4V/aFUaGKOypG+v+lUP v4EQ== 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=zXMUGHrVO2RyspFoRCi64LS7ltWbQ6WsPrrwMuR7B9k=; b=rCiYEot32DGlLbI25FGAUlXLWvM2GmbDfQsGM9U4oKjuearGuv5z/EDVmsBgGuGisC cFboXIJSalEGwugZAIAPjAGVKrij5CdiR4qaui/3RXRvjhLLYwdbaHwwARkg3FixdfUZ xxYl4ns3Gz0RnrmvTukcAb5R4GG4Vkv4+U4GKRKfAOpWeYHx0IHBxyCi1LhKq3ynbs3O gzRqFcy0A2Ml14wS+KPW1kaJ1gu4hOYCMplA4urINOMihsXZ+0yUIeokHB5AqMp0Q70d hKxYmuXnsz99ffTBOmKU66GT8Brx4dwjvPUrb528ENvXs+GiFjXovurIcsQbU2YG2GU4 1MMQ== X-Gm-Message-State: AOAM5308H332s5CeWOnkdpGl2ioTmhlLSmt9yFu1sggwgygwDJphT/w7 ofAQlzWj3GpbCGiwDq2kBo0AZrPgy/3Zddd6w6rwbSoTaE1Y/Q== X-Google-Smtp-Source: ABdhPJzqFEALcEZmxQLyW8/2WaZKCOS62E6KWqSw/Fe3xelGFa0OHNteGG5WDIihS3RCoyOUi/f6gkxHj2yNH6xEVQE= X-Received: by 2002:a25:32d5:: with SMTP id y204mr29947003yby.411.1604437785807; Tue, 03 Nov 2020 13:09:45 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 3 Nov 2020 22:09:33 +0100 Message-ID: To: PHP Internals List Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Nullsafe From: tovilo.ilija@gmail.com (Ilija Tovilo) Hey, On Tue, Nov 3, 2020 at 9:11 PM Marco Pivetta wrote: > Overall, "null safe" can be very dangerous if made the default. > > Here's a scenario where I'd never want "null safe" behaviour (which does > anything but introducing safety): > > ```php > $accounts->get($receiver) > ->addFunds( > $accounts->get($sender) > ->detractFunds($amount) > ); > ``` > > In the above scenario, if the first `$accounts->get()` call returns `null` > for any reason, you may actually destroy money (funds detracted, but never > added to another account). > > The example is simplistic, but it shows that "null safe" is everything but > "safe", and it must instead be used only where it absolutely makes sense to > suppress null reference errors. > > Similar behaviour can be observed around cast operators, which are too lax > for most businesses logic: > https://github.com/ShittySoft/symfony-live-berlin-2018-doctrine-tutorial/pull/3#issuecomment-460441229 > > Safe = crashes when it should crash. I agree. The goal here is not to never encounter a crash. The goal is to make dealing with known potential null values easier. Crashing is the safer behavior when something happens you might not have taken into account. Honestly, in hindsight "nullsafe" might not have been the best term. I adopted the term from the previous RFC. There are actually quite a few other languages that use the word "safe" for this feature. https://en.wikipedia.org/wiki/Safe_navigation_operator The most obvious alternative would be optional chaining. I'd suggest renaming it but I don't think that's viable at this point because those token names might already be used in various tools and extensions. Ilija