Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112171 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 39338 invoked from network); 3 Nov 2020 20:36:13 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Nov 2020 20:36:13 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A6FF91804D8 for ; Tue, 3 Nov 2020 11:56:42 -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=-0.7 required=5.0 tests=BAYES_05,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-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 11:56:39 -0800 (PST) Received: by mail-ed1-f47.google.com with SMTP id w1so18627590edv.11 for ; Tue, 03 Nov 2020 11:56:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=k05hAdB0YkJVBh7cD0tH/whzcj3dVyH1vsv10el11lM=; b=DV5I2K1cqe8mNWX42P7Amlu4gMBKgH0JzRX6nH9LVhy4/blJr7AHW2Ey2DIYNcPYrD ORlPC+xV1h960V75ihpeU5UM5DJWQryGxxmfWTvpw4kw70pVm/YiwSXm3vhFquwQezeQ MBdHTdxNiWI8PBAfLV2xowbMrWCnE0hHzLnMFs2gOBVKXW6h86U5WmPqeFg41CJfOkgQ zI0PWx2PXjEgd5Vn0LcbQt2Ut+S/y1L7BDxjHaUxYj11d1/2PUW5rR/zpXb90b3bz4nJ RxwKKS7CU5OdvaV2+L6bbFWr57DrJRm7dhL22Z1ON+pflePiW0tyNvtCxvW/RoDOWqby VYJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=k05hAdB0YkJVBh7cD0tH/whzcj3dVyH1vsv10el11lM=; b=SDYkJS1/eUHSjR8612p9jzzxC6/8ZbFG570D9SmhLlZTz9wfDSKSCLQH+PcEWhWG6I vI/yEDDm8PAAJx1AwfFQZpO4IkXiZHgn36ZIrq9ngyIp62YTzFTgU+uwXqwmC69MOZgq 2tAPpVFYqKr9dqFdpt7ynqDWfv0y6lL0nZ5C5n4QDZanyOQjIt+IB/IOgdQOOWaTogIA WIxgMuBrHe41T/5Qvh7EzAKEk9KVTWA3uoB2gE9CjeuPUhg5PqQQNNdStaYZ11T9bm9q 5249v9+YR6UM09VJw5SB9MVH9BHB1vIvOTM//hOa28GPEFembZEaWmdDNxqdsuUmnyFb ph5w== X-Gm-Message-State: AOAM533b18+OGDMAR/IOST0w2YHOlTZzrox0XPk4H8jH+amVzgti7Bqn 25l+R9rkyiCZxtITLy4QZJUplyEPfMBS3Q== X-Google-Smtp-Source: ABdhPJzaC237KS76un9ZRB5IlWixeV7V6IkAxLpOBhEMDtDfe9bpiKL3++iDdDS4Be7nt7LF4XDcXw== X-Received: by 2002:aa7:da0a:: with SMTP id r10mr8527772eds.102.1604433395659; Tue, 03 Nov 2020 11:56:35 -0800 (PST) Received: from claude.fritz.box ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id mj17sm5496782ejb.59.2020.11.03.11.56.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Nov 2020 11:56:34 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) In-Reply-To: Date: Tue, 3 Nov 2020 20:56:33 +0100 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <02527028-FDC9-4CE8-869B-8EDBFABE6DEA@gmail.com> References: To: Eugene Sidelnyk X-Mailer: Apple Mail (2.3608.120.23.2.4) Subject: Re: [PHP-DEV] Nullsafe From: claude.pache@gmail.com (Claude Pache) > Le 3 nov. 2020 =C3=A0 17:38, Eugene Sidelnyk a = =C3=A9crit : >=20 > 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? Hi, In a parallel world where people never commit bugs, yes, this is = reasonable semantics. However, it happens more than once that a null value occurs by accident = where an object is expected by the programmer. In this case, I very much = prefer to have a Warning or an Error, typically handled by an error = handler which sends a bug report to the developer, then triggers an = emergency stop. That makes it much easier to locate and fix bugs. Of course, this debuggability facility have to be balanced with the = inconvenience to having to write more code in cases where a null value = is expected. Having to write =E2=80=9C?->=E2=80=9D instead of =E2=80=9C->=E2= =80=9D in those cases is a minimal inconvenience. Here, I mean = =E2=80=9Cminimal=E2=80=9D in a very literal way: exactly one character = of difference. Also, there is the following benefit: When I write =E2=80=9C->=E2=80=9D, = I am stating that the LHS value should never be null; when I write = =E2=80=9C?->=E2=80=9D, I am stating that I expect that the LHS is = sometimes null. Thus, my code is documented in a very concise way = (between zero and one character), which is an aid for any future reader = (including myself). Aside: The name =E2=80=9Cnullsafe=E2=80=9D is misleading. The operator = is not about safety, it is about handling null values in a concise way. = In fact, in some circumstances, sweeping an unexpected null value under = the rug may be totally unsafe. =E2=80=94Claude=