Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118948 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 38288 invoked from network); 3 Nov 2022 08:30:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Nov 2022 08:30:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3449F180538 for ; Thu, 3 Nov 2022 01:30:27 -0700 (PDT) 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, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 3 Nov 2022 01:30:26 -0700 (PDT) Received: by mail-ed1-f52.google.com with SMTP id 21so1888627edv.3 for ; Thu, 03 Nov 2022 01:30:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=BgJzJOGXhOwwACm6+PqRj0E9In6ju4Aav0WvSD57PpE=; b=J1zBIL8WTlVzJNSrFhj/KoAz4NAv/a2PqxjGyc3yMjCxkRjU9HcuP01WogERfbqOlY FZwhJUUjXzwrayKWaGaYcKOy0jSSpyskzz53DOHvSkNr0wXTvB5qgH7XKtVIersOhOco lYkyLqRd1VVy6cFYw/ARR7tNU81Hxrkz8WHAdS6tX0KVrLXUidzbvsZ19AU/aHAByzaJ xn9nU3o8Job/dX7hWUZ+tARiB1Im2gM14dJ9ypSn+I8c+nzqBdFa6uhKrjScsDbn5GZo /ppWGojfMwZ8gK0W9fzRiB3mgHG9tL7EPGOpCbLEn0qD+9UONdoT0mYqmHVS+MufnpeP rTOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BgJzJOGXhOwwACm6+PqRj0E9In6ju4Aav0WvSD57PpE=; b=yP1RmMLzKB103NUCc5l1DTd2Mj9rULNFgGVz/DYKRJq+8Nf83/zajw8OYwuu7Mw2OS IcZa47BjFjGv0SHfM9BhLzJlYONMQCyRpiTVjZzhpdjY3E7ghOkrV7IBAEelI+Nm32CU kwfQpbC9qh7KBUWgcqMdlM6e25otKRO1NmMOZW7kOfsI4ujrpZXb2YPVPmrqLT/BUzsw CJ5wikEVP91/ln2BgIvGDX4atW7QPzn2nTEB5tvtNHDMgirdidBwHABMUHNDm2MDLw+/ u92a9fEJOt898Lx26rYm4/2FKWDNpygzD2fOUurEeLj3WhyPkliE+isU8mU6ljO6KPU2 Arhg== X-Gm-Message-State: ACrzQf3Ud5r+maPrBouwAp5cNBVzclTzd/To2qMDIUJTQ2jpZidxDd5F z4xyoulFTi72kwtp+w+8RYw= X-Google-Smtp-Source: AMsMyM6YXDMqpdaUF0+U4KHK7g460RQy/8WJZEkBEzWMDPAhUIfjRAX6VNcav9udHEOtTvFw9k2Cww== X-Received: by 2002:a05:6402:1c0a:b0:463:3cda:3750 with SMTP id ck10-20020a0564021c0a00b004633cda3750mr23210806edb.341.1667464225123; Thu, 03 Nov 2022 01:30:25 -0700 (PDT) Received: from smtpclient.apple ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id qq18-20020a17090720d200b007add62dafb7sm214308ejb.5.2022.11.03.01.30.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Nov 2022 01:30:24 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_B0BFD43B-1A92-4283-BB96-FD52A938177F" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Date: Thu, 3 Nov 2022 09:30:23 +0100 In-Reply-To: <13A9249B-C3B2-46E3-AB50-D46FAA2A301E@joshbruce.dev> Cc: Marco Pivetta , =?utf-8?Q?Micha=C5=82_Marcin_Brzuchalski?= , php internals To: Josh Bruce References: <21C5073D-3F39-49DA-8686-E027AE780793@joshbruce.dev> <1bc7759a-63b8-4b96-bb69-97b50f851307@www.fastmail.com> <94DC0839-E43B-4F3A-9105-8F3CB9D7BBC1@joshbruce.dev> <9AE33306-ED89-4FE4-86A5-89B4EDC81545@gmail.com> <13A9249B-C3B2-46E3-AB50-D46FAA2A301E@joshbruce.dev> X-Mailer: Apple Mail (2.3696.120.41.1.1) Subject: Re: [PHP-DEV] [RFC][Discussion] Objects can be declared falsifiable From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_B0BFD43B-1A92-4283-BB96-FD52A938177F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 3 nov. 2022 =C3=A0 02:51, Josh Bruce a =C3=A9cri= t : >=20 > Similar to: >=20 > function x(?SomeType $arg): ?SomeOtherType >=20 > Instead of: >=20 > function x(SomeType|null $arg): SomeType|null >=20 > Both are the same thing under the hood. The big difference between `?SomeType` shortcut and falsifiable object = feature, is that using `?SomeType` does not change the semantics of = `SomeType|null`, while declaring an object falsifiable changes the = semantics of `if ($obj)`. >=20 > In that same spirit, totally opt-in - not required to use or you can = get there some other way - similar to Marco=E2=80=99s comment around = __toString.=20 It is opt-in for the implementer of the library, not for the user of it, = as they are not necessarily the same person. Today, in a common situation where I know that a variable contains = either an object of some type or null, I routinely write `if ($a)` to = mean `if ($a !=3D=3D null)`. Now, with magic `__toBool()` possibly = implemented by the library=E2=80=99s author, I don=E2=80=99t know what = `if ($a)` means, unless I have carefully read the docs in order to know = whether they have opt into that misfeature, and, if so, what exactly = =E2=80=9Cfalsy=E2=80=9D means for them (invalid?, empty?, zero?). = Ironically, that will incite me to not use anymore the implicit casting = to bool for objects, and to write systematically `if ($a !=3D=3D null)`, = so that both myself and the reader of my code won=E2=80=99t have to look = at the docs in order to understand such simple code. =E2=80=94Claude= --Apple-Mail=_B0BFD43B-1A92-4283-BB96-FD52A938177F--