Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110879 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 70382 invoked from network); 8 Jul 2020 15:51:55 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Jul 2020 15:51:55 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EFA2A180384 for ; Wed, 8 Jul 2020 07:42:52 -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,MIME_QP_LONG_LINE, 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 cadetblue.birch.relay.mailchannels.net (cadetblue.birch.relay.mailchannels.net [23.83.209.28]) (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, 8 Jul 2020 07:42:48 -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 C29461813E3; Wed, 8 Jul 2020 14:42:46 +0000 (UTC) Received: from pdx1-sub0-mail-a10.g.dreamhost.com (100-96-23-13.trex.outbound.svc.cluster.local [100.96.23.13]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id F29151819DC; Wed, 8 Jul 2020 14:42:43 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|josh@joshbruce.dev Received: from pdx1-sub0-mail-a10.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); Wed, 08 Jul 2020 14:42:46 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|josh@joshbruce.dev X-MailChannels-Auth-Id: dreamhost X-Abortive-Average: 0006bed24dd5f75e_1594219366434_3190220458 X-MC-Loop-Signature: 1594219366434:2463388423 X-MC-Ingress-Time: 1594219366434 Received: from pdx1-sub0-mail-a10.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a10.g.dreamhost.com (Postfix) with ESMTP id ABC057E65B; Wed, 8 Jul 2020 07:42:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=joshbruce.dev; h= content-type:content-transfer-encoding:from:mime-version:subject :message-id:date:to:cc; s=joshbruce.dev; bh=qvgAh6pPVKsv6gPKre+F vG8KObA=; b=UQhHvk6ne+nviwDgrOjtjO7Om46pHDqCIcnDro52JEeg1Q2mRJJZ yeQ52ZXBYW6AQ00hgdh05OktH9VDapobQNwHWF48S2wWmAT1CgvnKnvwfNdXikJp F9bmxJhFbXMsTkHTgz4HJlvOgAcNodLvh7jfufo3cH0QntD+mEUFOR8= Received: from [192.168.86.34] (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-a10.g.dreamhost.com (Postfix) with ESMTPSA id 332247F7A6; Wed, 8 Jul 2020 07:42:43 -0700 (PDT) Content-Type: multipart/alternative; boundary=Apple-Mail-5858FA66-9135-4422-B2CF-09FC83F60991 Content-Transfer-Encoding: 7bit X-DH-BACKEND: pdx1-sub0-mail-a10 Mime-Version: 1.0 (1.0) Message-ID: <7E896FDC-D3D3-49F3-9B64-84C5A605B3B6@joshbruce.dev> Date: Wed, 8 Jul 2020 09:42:42 -0500 To: Rowan Tommins Cc: internals@lists.php.net X-Mailer: iPhone Mail (17F80) X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: 49 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduiedrudejgdekudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecuogfuuhhsphgvtghtffhomhgrihhnucdlgeelmdenucfjughrpegtgffhggfukfffvffosegrjehmrehhtdejnecuhfhrohhmpeflohhshhcuuehruhgtvgcuoehjohhshhesjhhoshhhsghruhgtvgdruggvvheqnecuggftrfgrthhtvghrnhepuefhvdehhefgueelleelgffhhedtgfffgffgfeejkeelkeeftdelgfeggeduhfegnecuffhomhgrihhnpehgihhthhhusgdrtghomhdpphhhphdrnhgvthdpvgigthgvrhhnrghlshdrihhopdgsihhtrdhlhienucfkphepudefiedrvdelrddugedtrddvudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopegludelvddrudeikedrkeeirdefgegnpdhinhgvthepudefiedrvdelrddugedtrddvuddprhgvthhurhhnqdhprghthheplfhoshhhuceurhhutggvuceojhhoshhhsehjohhshhgsrhhutggvrdguvghvqedpmhgrihhlfhhrohhmpehjohhshhesjhhoshhhsghruhgtvgdruggvvhdpnhhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth Subject: Re: [PHP-DEV] Proposal: A way for classes to define a response to any primitive type cast From: josh@joshbruce.dev (Josh Bruce) --Apple-Mail-5858FA66-9135-4422-B2CF-09FC83F60991 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable =EF=BB=BF > On Jul 7, 2020, at 3:24 PM, Rowan Tommins wrote:= >=20 >> On 07/07/2020 18:13, Josh Bruce wrote: >> Decided to put something together:https://github.com/joshbruce/external-p= roject-proposals/blob/master/php-concepts/interact-with-instance-as-php.md >=20 >=20 > Hi Josh, >=20 > Reading through this, it seems to cover a few different concepts, which ar= e certainly related, but not quite the same. >=20 > Firstly, we have interfaces such as Countable and Serializable, which don'= t make the object act like any particular primitive type, they just customis= e its interaction with particular functions. Iterators could potentially be i= ncluded in that category, too, because it's fairly easy to imagine the langu= age having multiple primitive types that can be iterated (e.g. separate "lis= t" and "dictionary" types). >=20 > ArrayAccess feels more explicitly about making an object "act like" an arr= ay, but more precisely it overloads the [] operator - it doesn't allow the o= bject to be used in other contexts where arrays are allowed. More general op= erator overloading was discussed recently, and the particular proposal put f= orward did not pass its RFC vote. [1] >=20 > __toString, on the other hand, only allows the object to be *converted to= * a string, not act like one. You can't, for instance, influence the behavio= ur of the concatenation operator, and make "Hello" . $object . "!" return an= object instead of a string, or a string that doesn't begin "Hello". An __to= Array method was proposed recently, to mixed reaction. [2] >=20 > The other closely related topic is what is often discussed as "scalar meth= ods" or "scalar objects" - the ability to call methods on non-object values,= and possibly to define your own methods that can be called in this way. Thi= s would seem to fit your use case with Shoop quite well: rather than Shoop::= array($array)->first()->unfold(), you would just call $array->first(). It's f= airly high on a lot of people's wish lists, but there's a lot of details to g= et right in both design and implementation, so I strongly recommend searchin= g for previous discussions and proofs of concept before diving in. >=20 >=20 > [1] https://wiki.php.net/rfc/userspace_operator_overloading > [2] https://externals.io/message/105589 >=20 > --=20 > Rowan Tommins (n=C3=A9 Collins) > [IMSoP] >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php All: Going to change threads now that I=E2=80=99m getting a better feel for t= he list environment and conventions, I think.=20 Someniatko: Saw the pipes RFC a while back and really appreciate. Think both= could have their place and developed preference (switch and if-else, for ex= ample). Added reference to document. See link below. Rowan: Thanks for the feedback and links! PHP Internals is definitely not my wheelhouse and I find myself speaking mai= nly from the developer=E2=80=99s perspective because I don=E2=80=99t know en= ough to speak from the PHP perspective. Thanks for your patience there. First takeaway is that I should drastically reduce scope and cut-short the b= ackground, lay of the land, sales pitch language I=E2=80=99ve seen in other R= FCs and concepts. Second, I should consider the audience more. Most of the people on this list= probably (read most definitely) know more about this than I do (or ever wil= l) and y=E2=80=99all don=E2=80=99t need long-winded explanations and backgro= und (could be wrong). So, thinking less text, more code. Finally, as I see more of the landscape and given conversations are low-band= width (long form, text-only), trying to cover more than one thing would most= likely distract at best and block at worst. So, gonna go after defining a boolean return value for a class. (At least fo= r now.) Updated: https://bit.ly/php-0001 Thank you again for the feedback and links. Cheers, Josh ps. The ability to call methods on non-object values is interesting and coul= d definitely be helpful for Shoop. The main frustration for me when using Sh= oop is the inability to just drop the pointer into a condition and have it w= ork. :) pps. The operator overloading feels like Swift=E2=80=A6nice feature...that w= ould definitely be helpful. While it doesn=E2=80=99t do the array thing itse= lf, I would be able to implement ArrayAccess and Iterator on it, yeah? At wh= ich point it could feel like an array (if I skimmed properly) - throw in __t= oString and we have the Pym primitive. :)= --Apple-Mail-5858FA66-9135-4422-B2CF-09FC83F60991--