Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112173 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42798 invoked from network); 3 Nov 2020 20:50:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Nov 2020 20:50:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2D89F1804D8 for ; Tue, 3 Nov 2020 12:11:09 -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-io1-f52.google.com (mail-io1-f52.google.com [209.85.166.52]) (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 12:11:08 -0800 (PST) Received: by mail-io1-f52.google.com with SMTP id u62so19799917iod.8 for ; Tue, 03 Nov 2020 12:11:08 -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=2D5YOtA7ONWn0JYPrYhYMUU6pSRe5SHIGpYSLMfpfu8=; b=tf9njeWPH4OlXbCral+RjU/hGkw+dUbHJlrMTwvCmpoItiUn2g40Q02TpuLXFmd8l1 RMWyRgpeQMK9w9xcoVF9KyzwkkPYBcvuLK0sq2DwhQtxkpAtxj4twOok6H22zdVGGuH3 snrTATfCGunRNY4GHQOsiqGBG/YrWNYdeLmBivQua+nHLFfm8XNAXLjh1js/T/IyvnBe 49Gyq3m6MQUrhwdJZnYWdDUkZlqbBGPGVH9bojo0FR5vaCMx4CU2ADimL7Uo/xKPjcR6 l1puT7n86R+pQpb8ciFDuTsoCKDjpH4vD+E0BAYBUPBK05YQb5Ny+WHa+9X48nWA4iyU MN/Q== 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=2D5YOtA7ONWn0JYPrYhYMUU6pSRe5SHIGpYSLMfpfu8=; b=jlKdQ/xGYQL0/l6exkYDALAnv1Hhb0iGsU0OZmKri2SjnQjjjxOnRFo/A/H2K1L1WZ Gek2trbwyF4QE2zICpXLdAwA9O0wleQHLpvg7xLe4JZePTdTSC0kX8jTeCRX9IsOJQ2A FRimcvkL2/sMicgCEUK9cjjXBPgXi6geWuYdcTw5prlIjabidlN3Uqjdn7IGRScPGYvN k6XWVIVE5IgK5Jt8WF9LtOPvWJQJOP8cRkJGatRfGVliWdZYFUnegDKzh71RYkWeCeYn eSn70UfzlaTNLPaRNDiZ2PZ0o4PNwDmRk9KT2ZJ7/Y/qsx+O8L9ufpUz037aHe7nuUp+ 1G9A== X-Gm-Message-State: AOAM533Dto1dUHV5lAXXJQxVvWSJCv3T+xyKLXJNHVxg3UnDHa9XgOok g0r3idhKmKrhRPxCugdkpFX9CaHCswl8b0OOAA8= X-Google-Smtp-Source: ABdhPJwRbzZUpoTJV5kD5bpDqF1XzQ/iTK/r4Tp3LkZKUisB1c1n7+jSGOx5Wgx4HWuQgQMKUVh7KQCzDdXTnZgEw9M= X-Received: by 2002:a6b:8b0d:: with SMTP id n13mr7366795iod.111.1604434267054; Tue, 03 Nov 2020 12:11:07 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 3 Nov 2020 21:10:54 +0100 Message-ID: To: Eugene Sidelnyk Cc: PHP Internals List Content-Type: multipart/alternative; boundary="0000000000008da94e05b33976a6" Subject: Re: [PHP-DEV] Nullsafe From: ocramius@gmail.com (Marco Pivetta) --0000000000008da94e05b33976a6 Content-Type: text/plain; charset="UTF-8" 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. > --0000000000008da94e05b33976a6--