Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112180 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 57650 invoked from network); 4 Nov 2020 19:18:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Nov 2020 19:18:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 10BD31804D8 for ; Wed, 4 Nov 2020 10:39:16 -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-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 ; Wed, 4 Nov 2020 10:39:15 -0800 (PST) Received: by mail-lf1-f46.google.com with SMTP id l28so28446376lfp.10 for ; Wed, 04 Nov 2020 10:39:15 -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=1s8KDgwlt0geoxUt6GCeryFlw4qryLD7iDAh9PSuMWs=; b=mOh3mDC6bPtgQ9NJjhj35h9R9U43+kt0UUGCHIwF3IO4kvnBnk8tsDxBCZmXf051cU TTppEcts93V2TBfLOXZyUmtILVjukog3a7qu4vL3U6WmJDQag5B3PKj3gOYwdgwZeEHy UozSLgt9UxmUa+wxi3UmFieiiwd/H1IJXaGeO5S2k6RMP5lfXpXhezsWP/RIeWQbWp6/ f8dgEUAGwSwbNwK2UNZdaSXH3bFEREP0seuhFl9BqvkPYupTaD/EBBOOx2Odno41moHp yPZLLwAed1Es8ew3th+369p01W05GqdBGVm2Q5abU4NiUpe4W9K3zVaTxbbeZf3ecxbD vDCw== 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=1s8KDgwlt0geoxUt6GCeryFlw4qryLD7iDAh9PSuMWs=; b=p0je/ditd/iKZ6tPw3kR9SrmZ9IfQVkYESDE0QxXs/e9g5/cVrwTNEVgj0JpjjLX9p 8/iF+npnEq1FGhBjNL6yWa92qFmlpfIKrZNYtJ8XPHToKK1u5WpBAkrREhDyakr7J0X4 qMgACPye24PfAMtF1Oh3tP5gGGheykyvkJQ8QMYrDwOFLtjNMSzIWWnt3U7/1s98GRNo JPbl4/5UjVlF6ScDt0C54cAPqKcWa0YWNjfPlmPgzJPTHn43Bb86dnw4WMSOoIZBGtTN V4iW5GKHxZIqE/unMJxO/iz84/rserg706qBrtSUdYvuy44VlJc9vV28T7nyPYO75e63 MJFA== X-Gm-Message-State: AOAM53350XC8R/em1wpqYpsewudz2IfzsuEN8iJ72joOVL/Kk+ehiLC2 OaUSO3wY2fzktxDJZSYV96xxG8X9cl1eJXrJSv0= X-Google-Smtp-Source: ABdhPJyKW9QBp4uvlXGlm+3XoUkxQGi3JLE/DwzUxvH7plMzaaA28UPMIliAuCdYim8xeb9TU3tE31F2KADQ4vtlZVc= X-Received: by 2002:ac2:5e64:: with SMTP id a4mr10831531lfr.109.1604515152303; Wed, 04 Nov 2020 10:39:12 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 4 Nov 2020 20:39:01 +0200 Message-ID: To: Marco Pivetta Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000b09bfb05b34c4b6d" Subject: Re: [PHP-DEV] Nullsafe From: zsidelnik@gmail.com (Eugene Sidelnyk) --000000000000b09bfb05b34c4b6d Content-Type: text/plain; charset="UTF-8" Thus, can you provide any other dangerous example? On Wed, Nov 4, 2020, 6:59 AM Eugene Sidelnyk wrote: > But wait! > > In your example, funds won't get detracted. If `$accounts->get($receiver)` > will return `null`, then everything inside `addFunds(...)` will not be > executed. > Your example (simplified): https://3v4l.org/38Dk3 > > Another one: > ```php > function expensive_function() { > var_dump(__FUNCTION__); > } > > $foo = null; > > $foo?->baz(expensive_function()); > ``` > > 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. >> >>> --000000000000b09bfb05b34c4b6d--