Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118947 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 13178 invoked from network); 3 Nov 2022 01:51:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Nov 2022 01:51:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 000541804BA for ; Wed, 2 Nov 2022 18:51:31 -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=-0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLACK autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS36483 23.83.208.0/21 X-Spam-Virus: No X-Envelope-From: Received: from bumble.birch.relay.mailchannels.net (bumble.birch.relay.mailchannels.net [23.83.209.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 2 Nov 2022 18:51:30 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|josh@joshbruce.dev Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 7C88A5C0F2E; Thu, 3 Nov 2022 01:51:29 +0000 (UTC) Received: from pdx1-sub0-mail-a241 (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 040A75C0BB9; Thu, 3 Nov 2022 01:51:29 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1667440289; a=rsa-sha256; cv=none; b=GlWV7d+oGcPj6HcoGXimmSr/ezrLDo8hr9Z4xkANNhNqWt7CSVXias/oLKQay8HhqR0lui kA6+7OFKr25fdttp/p9VHiyF2AJXZN34fMq8wxIynCPbAidRO8U/v5QV6RicjPfJn9EPPm f7ki5U8hAZAT4MB2Z/T5EIJlNTKEcK4QDLN3FZBF3yezCM4BYflvNiZQwzGpDRJ2znPGCc 7DHVy7OEchXinrj1uuhMJ0cjCsYmtGLXAdghq3ffhPmWcCglfnMa+sqlI4aOTDmAgJ5j4W HA/cRx425lFpU0tVkkf8RFV95v2HtY7gyucWfIhFPOppbYVPnDPK1Fy7aFQLPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1667440289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LtbY1fDtTCwTvrZ7DEnIYqqq5gJxzYyOLDSwHom0sEM=; b=jmBevKy/bPsnm87/WvNDNw4s/NRdHCdc6bhHmuXcEoN8pIo0rlHJOYqKIYTw5+Atx+WfmN eqElg8JUqrEttPIpzdd9JzIEGYZa2rvugzrXTCkZtcdmBx2AWGCnhu2j4m/D6hcnLI0Jcq Kw21UvgJcfl4j/FfWxjjpbpZmEexRr+7XRcdMiA7nEUUKXfZU3xXZr+wW3PyaHafl+Z3sc Qb+/+sAsES72Ec4IFKsC1ZWxpt0lweQ84X0GfeCf/VpsOJmpFf83g5XixqpIsGe32ngTny FJDALPylYWfDgxEDN3xqIauz0UmBmejc3x6JrgVILiIATDgAORSsGwC3GFbPOg== ARC-Authentication-Results: i=1; rspamd-7b8dfb6d4c-gtlhx; auth=pass smtp.auth=dreamhost smtp.mailfrom=josh@joshbruce.dev X-Sender-Id: dreamhost|x-authsender|josh@joshbruce.dev X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|josh@joshbruce.dev X-MailChannels-Auth-Id: dreamhost X-Whimsical-Tank: 32fef799064fd677_1667440289280_3000626902 X-MC-Loop-Signature: 1667440289280:2871528966 X-MC-Ingress-Time: 1667440289280 Received: from pdx1-sub0-mail-a241 (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.123.200.76 (trex/6.7.1); Thu, 03 Nov 2022 01:51:29 +0000 Received: from smtpclient.apple (111.sub-75-244-34.myvzw.com [75.244.34.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: josh@joshbruce.dev) by pdx1-sub0-mail-a241 (Postfix) with ESMTPSA id 4N2mvN3M43z39; Wed, 2 Nov 2022 18:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joshbruce.dev; s=dreamhost; t=1667440288; bh=djuLJAFaUmRodpZ2KbD0PkFEfj4bB3wjnjRKHSUr8Nw=; h=From:Content-Type:Subject:Date:Cc:To; b=ek2S+Qd0g2i/mG+X2CBmV3VWc6uoL3KnWHJeoGMXIb/0gtsAIKjziDTyb7pBRZVC9 YVukWoZiv6Pf4YS36ayHAkMma5Y+nGdg8flzumIRkAdMm9eSIBbSvf2s/c5dWgytia 7PupwoK3aQzsXiOW1kw+Da6EENExdgH5tQMFO3bTUcljw4D7D9m/ZjrCurZvugdS9y PnktkeykPuBCWkLV+7U17493i962xLorkVa4zBOZRWhHUkBmKYaqles6JvM4AcGf3O 8vflWlZ/5P5OYIKQt8GWRio+Knr23BUukCrH/bwMxA/qhszhUVm2NEl9rol9jJrJ+w 40K2fHoVKDeAg== Message-ID: <13A9249B-C3B2-46E3-AB50-D46FAA2A301E@joshbruce.dev> Content-Type: multipart/alternative; boundary="Apple-Mail=_58786CE2-9860-48F6-BEE3-999B6C10896C" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.200.110.1.12\)) Date: Wed, 2 Nov 2022 21:51:16 -0400 In-Reply-To: Cc: Claude Pache , =?utf-8?Q?Micha=C5=82_Marcin_Brzuchalski?= , php internals To: Marco Pivetta 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> X-Mailer: Apple Mail (2.3731.200.110.1.12) Subject: Re: [PHP-DEV] [RFC][Discussion] Objects can be declared falsifiable From: josh@joshbruce.dev (Josh Bruce) --Apple-Mail=_58786CE2-9860-48F6-BEE3-999B6C10896C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Thank you all for the engagement so far. (Note: All scalar types and one compound type can be cast as true or = false natively - of the scalar and compound types, callable and object = are the only two with no, native false representation.) > Have you tried not initializing invalid objects? This could help you. = Also that sounds more logical to me as I don't see any reasons to = initialize invalid objects if it's a matter of simple validation = instead. I've tried valid objects (multiple approaches) - and I=E2=80=99m using = the term valid loosely because the instances are not, technically, = invalid in the strictest sense. I=E2=80=99m using =E2=80=9Cvalid=E2=80=9D = and =E2=80=9Cinvalid=E2=80=9D as method names in the implementation = because I don=E2=80=99t have a better word to describe the concept; = still looking. If you'd like to hear more, please let me know and I can = detail out other approaches, which are pretty standard.=20 I only used it as an example of what would be possible and trying to = illustrate using a real world example of the problem-space. With that said, the RFC isn=E2=80=99t meant to directly solve an = implementation issue that can=E2=80=99t be solved any other way; it=E2=80=99= s more syntax, style, and consistency (see note above).=20 Similar to: function x(?SomeType $arg): ?SomeOtherType Instead of: function x(SomeType|null $arg): SomeType|null Both are the same thing under the hood. 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 For example, I actively avoid null and don=E2=80=99t use most = null-related things available in PHP and tend to wrap objects, methods, = and functions that might return null=E2=80=A6but, if you=E2=80=99re into = null, don=E2=80=99t let me stop you. :) (I also tend to wrap objects, methods, and functions that return bool = and some other type to put them in a context where I get one or the = other, but not either-or - file_put_contents, for example=E2=80=A6big = fan of single return types.) > The one situation in which I can think of where an object might = legitimately have a falsey bool casting is if it represents a single = value I see that, though I don=E2=80=99t necessarily agree. To use similar language, the object could represent a single, complex = concept (especially through composition) - not just a single value.=20 A car without a blinker is still a car and usable for most things it was = designed for - and there could be a fallback for the missing blinker; = valid instance with a non-blocking deficiency: = https://www.dmv.org/how-to-guides/hand-signals-guide.php >>> P.S. I don't see it feasible to have objects that evaluate false in = logical expressions. I=E2=80=99m interested in more detail on this.=20 Feasible as in not possible to do easily? Not possible in general? Or, = something else?=20 > For better or for worse (IMHO, for worse), `SimpleXMLElement` = instances representing attributeless empty elements are already falsy, = so yes, it is absolutely feasible. Interesting use case. Haven=E2=80=99t used SimpleXMLElement enough to = comment. Interested to hear more. > This is absolutely terrifying. Not sure if this is referring to the SimpleXMLElement reference or = beyond it. :) Cheers, Josh > On Nov 2, 2022, at 2:09 PM, Marco Pivetta wrote: >=20 > On Wed, 2 Nov 2022 at 18:51, Claude Pache = wrote: >=20 >>=20 >>=20 >>> Le 2 nov. 2022 =C3=A0 09:12, Micha=C5=82 Marcin Brzuchalski < >> michal.brzuchalski@gmail.com> a =C3=A9crit : >>>=20 >>> P.S. I don't see it feasible to have objects that evaluate false in >>> logical expressions. >>=20 >> For better or for worse (IMHO, for worse), `SimpleXMLElement` = instances >> representing attributeless empty elements are already falsy, so yes, = it is >> absolutely feasible. >>=20 >> =E2=80=94Claude >=20 >=20 > This is absolutely terrifying. >=20 > Marco Pivetta >=20 > https://twitter.com/Ocramius >=20 > https://ocramius.github.io/ --Apple-Mail=_58786CE2-9860-48F6-BEE3-999B6C10896C--