Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111049 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 26691 invoked from network); 16 Jul 2020 16:35:58 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Jul 2020 16:35:58 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6DC0618055B for ; Thu, 16 Jul 2020 08:28:55 -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,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 dog.birch.relay.mailchannels.net (dog.birch.relay.mailchannels.net [23.83.209.48]) (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:28:54 -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 EEF9D401478; Thu, 16 Jul 2020 15:28:52 +0000 (UTC) Received: from pdx1-sub0-mail-a42.g.dreamhost.com (100-96-5-126.trex.outbound.svc.cluster.local [100.96.5.126]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 46BBE401660; Thu, 16 Jul 2020 15:28:52 +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:28:52 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|josh@joshbruce.dev X-MailChannels-Auth-Id: dreamhost X-Thoughtful-Unite: 2fd50c7e25aa55c5_1594913332749_434023787 X-MC-Loop-Signature: 1594913332749:2864499238 X-MC-Ingress-Time: 1594913332749 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 62E1886077; Thu, 16 Jul 2020 08:28:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=joshbruce.dev; h=from :message-id:content-type:mime-version:subject:date:in-reply-to :cc:to:references; s=joshbruce.dev; bh=QGPmCb0iJBl2j17OdX3CI1FXf to=; b=Sxp3lYB/7Ckq9XBKPo8NEcJwhZafGWNEI+aHmFiHfJcDqZxzJs4/SsS6l VESaU3VV8Gc3XrZ7NhiUqo1OGIoZRbKjbbm1/F4T7wJKjbisy6WFTKcVoLmdZh7D /7YI7Sz24eKcm64zJvAH/og7zzzRyl7SMClPbMIIEIz+kZ37V8= 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 D596386096; Thu, 16 Jul 2020 08:28:48 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a42 Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_8CE391CA-A49D-48F7-852A-27E4A7AFB5F4" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Date: Thu, 16 Jul 2020 10:28:47 -0500 In-Reply-To: Cc: Larry Garfield , php internals To: Matthew Brown References: <21C5073D-3F39-49DA-8686-E027AE780793@joshbruce.dev> <132a2f9c-331c-48c9-8c15-f0f7c9392341@www.fastmail.com> X-Mailer: Apple Mail (2.3608.80.23.2.2) X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduiedrfeeggdeklecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhkfgtggfuffgjvfhfofesrgdtmherhhdtjeenucfhrhhomheplfhoshhhuceurhhutggvuceojhhoshhhsehjohhshhgsrhhutggvrdguvghvqeenucggtffrrghtthgvrhhnpefgteevhedugfekgfevudffgedugfeuiedulefhveetkeehhfeludekfeevhefffeenucffohhmrghinhepphhhphdrnhgvthenucfkphepudefiedrvdelrddugedtrddvudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopehjohhshhhsqdhmsghprdhlrghnpdhinhgvthepudefiedrvdelrddugedtrddvuddprhgvthhurhhnqdhprghthheplfhoshhhuceurhhutggvuceojhhoshhhsehjohhshhgsrhhutggvrdguvghvqedpmhgrihhlfhhrohhmpehjohhshhesjhhoshhhsghruhgtvgdruggvvhdpnhhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth Subject: Re: [PHP-DEV] [RFC][Discussion] Objects can be declared falsifiable From: josh@joshbruce.dev (Josh Bruce) --Apple-Mail=_8CE391CA-A49D-48F7-852A-27E4A7AFB5F4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 https://wiki.php.net/rfc/objects-can-be-falsifiable = Updates: - 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). All: 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. :) To Larry=E2=80=99s user example.=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). 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). (Maybe that should be a table as well??) print null; // always succeeds despite being nothing - not a fatal error (bool) null; // always succeeds - always false (integer|float) null; // always succeeds - always 0 (array) null; // always succeeds - always [] (string) null; // always succeeds - always =E2=80=9C" null->someMethod(); // always fails - crashes app 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 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) > 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). David: Completely agree on respecting new users and devs (see opening = bit). 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 > (bool) cast working together with __toBool() is a good one, but I = think that it is being discussed in another topic. Was it an RFC or email??=20 If email and within the last week or so, it might be this same = conversation.=20 Took a moment to evolve to this kinda hybrid approach. (In short, back = to the original implementation, with a pretty different rationale.) > The other implication is that this is now possibly *not* a bug: >=20 > if (!$foo) { > $foo->bar(); > } 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 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). 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. 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. > "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? Larry: Totally lifted from the Stringable RFC - lol: = https://wiki.php.net/rfc/stringable = - string|Stringable 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: $object =3D new \stdClass(); $object->__toBool =3D function() {=20 return false|true;=20 }; if (! $object) { // made it } > "(Including __construct() replacing old style constructors in PHP 7.)" = - __construct replaced old-style constructors in PHP 5. :-) Here=E2=80=99s where I got that from: = https://www.php.net/manual/en/migration70.deprecated.php = 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. > 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! Thanks for the table suggestion!=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. 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?? > Let's not confuse Java nullable issues with PHP nullability, which is = quite > healthy :-) Marco: To be fair, I don=E2=80=99t know anything about Java=E2=80=99s = nullable issues - only PHP's. :) > 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 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.) 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. Cheers, Johs --Apple-Mail=_8CE391CA-A49D-48F7-852A-27E4A7AFB5F4--