Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111051 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 29560 invoked from network); 16 Jul 2020 16:38:52 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Jul 2020 16:38:52 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C09E91804DA for ; Thu, 16 Jul 2020 08:31:50 -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,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 cheetah.birch.relay.mailchannels.net (cheetah.birch.relay.mailchannels.net [23.83.209.34]) (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 ; Thu, 16 Jul 2020 08:31:49 -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 AD76440098E; Thu, 16 Jul 2020 15:31:48 +0000 (UTC) Received: from pdx1-sub0-mail-a42.g.dreamhost.com (100-96-9-43.trex.outbound.svc.cluster.local [100.96.9.43]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 30F62400A4E; Thu, 16 Jul 2020 15:31:42 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|josh@joshbruce.dev Received: from pdx1-sub0-mail-a42.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.18.8); Thu, 16 Jul 2020 15:31:48 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|josh@joshbruce.dev X-MailChannels-Auth-Id: dreamhost X-Spicy-Name: 2251f17d409870d6_1594913508527_2453484157 X-MC-Loop-Signature: 1594913508527:3436401359 X-MC-Ingress-Time: 1594913508527 Received: from pdx1-sub0-mail-a42.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a42.g.dreamhost.com (Postfix) with ESMTP id C97398609A; Thu, 16 Jul 2020 08:31:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=joshbruce.dev; h= content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; s= joshbruce.dev; bh=YqoVBTFRM3rLC7nFPKIeTRHxE1o=; b=V1isNC5LL7GemU kN/hwTiA5F1xnQy3ZG0CM0XZGTR9gdFYyC3bveGPGIFlyoFdq7BgxhWhLQ0y37OG enBbTKDmBoOVd3LNOqsj19FZmflXJ08fSQ79nEEIR+KLJbb2x3gIE8WXCbiUbgFm DB+JJVUR3WtxPcKmjusnV6ENx6K6U= Received: from joshs-mbp.lan (21.140.29.136.in-addr.arpa [136.29.140.21]) (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-a42.g.dreamhost.com (Postfix) with ESMTPSA id 6F25B86097; Thu, 16 Jul 2020 08:31:40 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) X-DH-BACKEND: pdx1-sub0-mail-a42 In-Reply-To: Date: Thu, 16 Jul 2020 10:31:39 -0500 Cc: Larry Garfield , php internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <21C5073D-3F39-49DA-8686-E027AE780793@joshbruce.dev> <132a2f9c-331c-48c9-8c15-f0f7c9392341@www.fastmail.com> To: Matthew Brown X-Mailer: Apple Mail (2.3608.80.23.2.2) X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduiedrfeeggdeltdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpegtggfuhfgjfffgkfhfvffosehtqhhmtdhhtdejnecuhfhrohhmpeflohhshhcuuehruhgtvgcuoehjohhshhesjhhoshhhsghruhgtvgdruggvvheqnecuggftrfgrthhtvghrnheptdeftdfhheffteethedukeeigfetvdevhefhudejffdttdffteefjeeffeeivdefnecuffhomhgrihhnpehphhhprdhnvghtnecukfhppedufeeirddvledrudegtddrvddunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhppdhhvghlohepjhhoshhhshdqmhgsphdrlhgrnhdpihhnvghtpedufeeirddvledrudegtddrvddupdhrvghtuhhrnhdqphgrthhhpeflohhshhcuuehruhgtvgcuoehjohhshhesjhhoshhhsghruhgtvgdruggvvheqpdhmrghilhhfrhhomhepjhhoshhhsehjohhshhgsrhhutggvrdguvghvpdhnrhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght Subject: Re: [PHP-DEV] [RFC][Discussion] Objects can be declared falsifiable From: josh@joshbruce.dev (Josh Bruce) > On Jul 16, 2020, at 10:28 AM, Josh Bruce wrote: >=20 > https://wiki.php.net/rfc/objects-can-be-falsifiable = >=20 > Updates: >=20 > - Open issues (outstanding questions/concerns) updated > - Future scope > - References now have links to original copies on GitHub (still = updating 0002) - will be removed if accepted and implemented. > - No violent opposition, but concerns - will be looking at how to = implement (or set up implementing). >=20 > All: >=20 > Trying to let conversation flow w/o me; sticking to once a day batch = updates. Let me know if you=E2=80=99d prefer something else - still = learning the Roman-way. :) >=20 > To Larry=E2=80=99s user example.=20 >=20 > With Falsifiable the User instance becomes more self-aware. = __toBool(), which might be more for the object itself, other objects, or = PHP itself through a universal, reserved API entry point (like other = magic methods). >=20 > Trying to make PHP fail gracefully more by adding to the ability of = not returning null (or interacting with null - nullsafe, optionals, and = so on). >=20 > (Maybe that should be a table as well??) >=20 > print null; // always succeeds despite being nothing - not a fatal = error >=20 > (bool) null; // always succeeds - always false >=20 > (integer|float) null; // always succeeds - always 0 >=20 > (array) null; // always succeeds - always [] >=20 > (string) null; // always succeeds - always =E2=80=9C" >=20 > null->someMethod(); // always fails - crashes app >=20 > I was in the conversations leading up to null being able to handle = this much interaction, part makes me go back to something talked about = re new developers (paraphrased): It's frustrating to learn software = development when it takes a lot to set up and with every turn you take = your app crashes - people give up; so, PHP prefers failing gracefully = over hard crashes.=20 >=20 > The only interaction on null that seems to fail outright (from = personal experience) is trying to call a method because it=E2=80=99s not = an object. (It doesn=E2=80=99t even fail the dread array-to-string = conversion. lol) >=20 >> I really appreciate any effort that can make PHP a more powerful = language. However, for this item, I believe it will generate much = greater cognitive complexity for new users (and I hate to assume that = this is a problem, but we have to remember our roots). >=20 > David: Completely agree on respecting new users and devs (see opening = bit). >=20 > I=E2=80=99m thinking right now, for me, it=E2=80=99s more about always = being able to message the type you expect, even if false (in the = abstract), while also letting PHP to interact automatically with it in = the ways we have also become accustomed.=20 >=20 >> (bool) cast working together with __toBool() is a good one, but I = think that it is being discussed in another topic. >=20 > Was it an RFC or email??=20 >=20 > If email and within the last week or so, it might be this same = conversation.=20 >=20 > Took a moment to evolve to this kinda hybrid approach. (In short, back = to the original implementation, with a pretty different rationale.) >=20 >> The other implication is that this is now possibly *not* a bug: >>=20 >> if (!$foo) { >> $foo->bar(); >> } >=20 > Matthew: I can see that feeling like a bug, for me it would be a = feature (can=E2=80=99t believe I just said that).=20 >=20 > Objects that return an abstracted (high-level) false, can tell me why = (without blowing things up via fatal errors or added syntax and time of = try-catch-throw or various permutations of optionals, which is possibly = frustrating for new devs - possibly specific to the self-taught, it was = for me back in the day - still don=E2=80=99t have the muscle memory for = try-catch-throw and implementing errors). >=20 > I can=E2=80=99t ask null any questions - it exists only in the mind = (so to speak), but I can send messages to an instance that is abstractly = false. (And remove all the null-checks and optionals from (at least) my = code that uses it or wraps some package that doesn=E2=80=99t. >=20 > My contract with a function call becomes: You will always get = something of this type - period. Whether it=E2=80=99s the one you = specifically wanted, that would be debatable, but it will be that type. >=20 >> "Further, the union type bool|Falsifiable will be dynamically added = at run time to any object implementing the reserved __toBool() method, = which would allow stdClass() objects to be defined as Falsifiable also. = " >>=20 >> What's that about? >=20 > Larry: Totally lifted from the Stringable RFC - lol: = https://wiki.php.net/rfc/stringable = - string|Stringable >=20 > And I don=E2=80=99t know of a way to add an interface to `new = stdClass()` - but thought this might be a valid use case: >=20 > $object =3D new \stdClass(); > $object->__toBool =3D function() {=20 > return false|true;=20 > }; >=20 > if (! $object) { > // made it > } >=20 >> "(Including __construct() replacing old style constructors in PHP = 7.)" - __construct replaced old-style constructors in PHP 5. :-) >=20 > Here=E2=80=99s where I got that from: = https://www.php.net/manual/en/migration70.deprecated.php = >=20 > Might have been tired when reading it. Are old style constructors = still available at all in PHP 7 (just deprecated)?? Looking for when old = constructors were removed - not just deprecated. >=20 >> I think the truth tables have a formatting error; check the last line = that goes wider than the rest. Also, watch out for "smart quotes" in = the string parts. Also, YAY summary tables! >=20 > Thanks for the table suggestion!=20 >=20 > Not sure I=E2=80=99m getting the same issue. If you mean the line that = starts with =E2=80=9Crow 1=E2=80=9D - this is a different paragraph, not = part of the table - its width is styled wider than the table. = Margin-bottom is 1.5rem on paragraph - 0 on the table; so, they butt = against one another. >=20 > Is there a way to add an empty line (don=E2=80=99t recall seeing it in = the wiki syntax)?? Or, are you noticing something else?? >=20 >> Let's not confuse Java nullable issues with PHP nullability, which is = quite >> healthy :-) >=20 >=20 > Marco: To be fair, I don=E2=80=99t know anything about Java=E2=80=99s = nullable issues - only PHP's. :) >=20 >> BTW, I'm not saying you should pursue both RFCs or anything, that's >> just a reference in case you are looking around how others did it.=20 >=20 > Marcio: Thanks for the example! I=E2=80=99ve never used a language = that has this as a possibility by this type of implementation - Swift is = capable by way of overloading operators (at least last I used it). = Definitely would like more examples of languages that do something like = this. (Links to those conversations to glean high-level concerns and = possible problems might be helpful as well.) >=20 > Definitely not looking to pursue both at this time as emptiness or = nonzero is harder for me to justify to myself, much less the larger = community - not that it shouldn=E2=80=99t happen. >=20 > Cheers, > Johs >=20 Apologies: I was NOT in the conversations leading up to null=