Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112177 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 90670 invoked from network); 4 Nov 2020 05:17:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Nov 2020 05:17:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B3F8E1804D1 for ; Tue, 3 Nov 2020 20:38:10 -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,HTML_MESSAGE, 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-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 20:38:09 -0800 (PST) Received: by mail-lj1-f177.google.com with SMTP id 2so21492052ljj.13 for ; Tue, 03 Nov 2020 20:38:09 -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 :cc; bh=EwmPO3Yv0GojqGvix99ikgK+LtBVYwVhUa/AhHlbKHo=; b=qimOJgoS1VZ+xsVJHKyF84RyttiiTXOs7MuXppvrL0IGg58JeKjX4eP3n+5BjZcl8p qbR4OVLzC2/oeqlSUG7rthb+NV4NWTE800uruxWlWg1X3Ose7n3MlN81d6RyXsmb1hFl wSbLGqJua9pR5RN4evf5QItJSqAPCEk/Hwv4kq1Ed0wBAJbCecW8panJ2Cw4s5anSgE/ drATa1zo53xmPlkKpymaBg4QCdZe5bHGCqrZXxCXDNM4nJRTP/UMTWAxTnQ3Df41KdAp dsei1YazObHvQGFaHSNnxxw3/t1leicTJeEIK9DuX3MWkyEv71DYMz3YQCC6KYoJP7od cDtg== 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=EwmPO3Yv0GojqGvix99ikgK+LtBVYwVhUa/AhHlbKHo=; b=HjQ+g7WkOldv/lBgGv00M/4UjV79tFzZRjxX25GzgCU4OVkGdG+rnsdyyVDOPBNrat dBeFEh1HdoNX4sG2tMXE3zh5iFAtIvSqn7QJrt+9KLGKZkrBOZ9wNPBwSJtcA3hhX5XT trFAa1eyGTUkzH2mHZqHW5Oy7k56B3tD/VnCRZKj7IPQzrmey11fT3LA3KTj0c3v2E1n AywT9XcAZECeb2/VraWQg0k3XsPfIOpfu9g2FgvTzcEplt4bbX5wQ2v0UBcJt38N3BLg DEL5F2HfeVOcJadc4r1dc92MOLaplhTv9FxWFNR2MrIsvLp2RCLFObyDWIRXPYTECVp5 mh8g== X-Gm-Message-State: AOAM531CRMlQy+P1KXHbv/lwG6uXkKHxjdNNzDZnsv+0jZ5GHpziKDdZ sm8TtFtzpoGG8GGgCLz/reTuQ7pNqzEGWiemz4g= X-Google-Smtp-Source: ABdhPJzIyMYVEz4NXnrnKv/LqTvpGbvuiPvobk9jFqBAET8qFut/43LrkNx24JUdrLLoRA1tBvr484EWORCcJ8mkP5I= X-Received: by 2002:a2e:8ed1:: with SMTP id e17mr10537346ljl.114.1604464688387; Tue, 03 Nov 2020 20:38:08 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 4 Nov 2020 06:37:56 +0200 Message-ID: To: Marco Pivetta Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000ce5cac05b3408b71" Subject: Re: [PHP-DEV] Nullsafe From: zsidelnik@gmail.com (Eugene Sidelnyk) --000000000000ce5cac05b3408b71 Content-Type: text/plain; charset="UTF-8" Hm, yes. If the `get()` method can return `null`, then it is a problem. Currently `null` is abused to indicate that value was not found. `NotFoundException` should be thrown instead. But.. yeah, we can't just use `nullsafe` by default because of abuse of `null`. On Tue, Nov 3, 2020 at 10:11 PM Marco Pivetta wrote: > Heya, > > On Tue, Nov 3, 2020, 17:38 Eugene Sidelnyk wrote: > >> Hello, internals! >> I am wondering why don't we use ordinary `->` operator with safe null >> handling? Programmers will be more prone to return null values. And thus, >> in most of cases `?->` will replace `->`. >> Why do we need another operator, if we can implement null safe in current >> operator without BC breaks? >> > > 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. > >> --000000000000ce5cac05b3408b71--