Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110866 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 80098 invoked from network); 7 Jul 2020 18:23:18 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Jul 2020 18:23:18 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 78DE118050A for ; Tue, 7 Jul 2020 10:14:01 -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, SPF_HELO_NONE,SPF_PASS 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 bee.dogwood.relay.mailchannels.net (bee.dogwood.relay.mailchannels.net [23.83.211.14]) (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 ; Tue, 7 Jul 2020 10:13:58 -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 B461B341BFB; Tue, 7 Jul 2020 17:13:56 +0000 (UTC) Received: from pdx1-sub0-mail-a16.g.dreamhost.com (100-96-12-18.trex.outbound.svc.cluster.local [100.96.12.18]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 5668C341E45; Tue, 7 Jul 2020 17:13:42 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|josh@joshbruce.dev Received: from pdx1-sub0-mail-a16.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); Tue, 07 Jul 2020 17:13:56 +0000 X-MailChannels-SenderId: dreamhost|x-authsender|josh@joshbruce.dev X-MailChannels-Auth-Id: dreamhost X-Vacuous-Blushing: 4331e92964b881f3_1594142026604_802572558 X-MC-Loop-Signature: 1594142026604:2555948432 X-MC-Ingress-Time: 1594142026604 Received: from pdx1-sub0-mail-a16.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a16.g.dreamhost.com (Postfix) with ESMTP id E20297FFB0; Tue, 7 Jul 2020 10:13:41 -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=ggivqwQ54NiV/+XcYJBafp0bw TM=; b=pebSZ+9RN/hkdLaL+YueHLrA9s4vH2XKRV4Wk/znJU+6r8VrDoMBs2iIp hG9llMSIrokEmJQ+7EOdRq3+jOgrRw72L3k653D9FrCw+b/ovilQOuIm9AI+wykS HkhhbbSatQf6DNMFoi/h16HmdsIoGkGsHCL2+VXciJTOyuEA5k= 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-a16.g.dreamhost.com (Postfix) with ESMTPSA id 345707FF27; Tue, 7 Jul 2020 10:13:41 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a16 Message-ID: <15F2E346-4B74-401D-9993-0DFAE8C0A988@joshbruce.dev> Content-Type: multipart/alternative; boundary="Apple-Mail=_C49E08D3-611E-4A39-8625-AB4E3D73F449" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Date: Tue, 7 Jul 2020 12:13:39 -0500 In-Reply-To: Cc: PHP Internals List To: Marco Pivetta References: <0431210B-417F-4576-BF28-E51ECFA8F3EF@joshbruce.dev> X-Mailer: Apple Mail (2.3608.80.23.2.2) X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduiedrudehgddutdegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpffftgfetoffjqffuvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffktgggufffjgfvfhfosegrtdhmrehhtdejnecuhfhrohhmpeflohhshhcuuehruhgtvgcuoehjohhshhesjhhoshhhsghruhgtvgdruggvvheqnecuggftrfgrthhtvghrnhepfeelgffgffffgeevleefheefhfektdeltdffleetfefggeffuedvheelheehjefgnecuffhomhgrihhnpegvgihtvghrnhgrlhhsrdhiohdpghhithhhuhgsrdgtohhmpdhtfihithhtvghrrdgtohhmpdhsthgrtghkohhvvghrfhhlohifrdgtohhmnecukfhppedufeeirddvledrudegtddrvddunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhppdhhvghlohepjhhoshhhshdqmhgsphdrlhgrnhdpihhnvghtpedufeeirddvledrudegtddrvddupdhrvghtuhhrnhdqphgrthhhpeflohhshhcuuehruhgtvgcuoehjohhshhesjhhoshhhsghruhgtvgdruggvvheqpdhmrghilhhfrhhomhepjhhoshhhsehjohhshhgsrhhutggvrdguvghvpdhnrhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght 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=_C49E08D3-611E-4A39-8625-AB4E3D73F449 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jul 6, 2020, at 11:54 AM, Marco Pivetta wrote: >=20 > Hey Josh, >=20 > Similar proposals were raised recently for `__toArray()`: see > https://externals.io/message/108369#108369 >=20 > I'd endorse avoiding object-to- casts via cast operations: = they are > a good source of bugs. > My rationale for the discouragement of magic cast methods is explained = with > some code examples at > = https://github.com/ShittySoft/symfony-live-berlin-2018-doctrine-tutorial/p= ull/3#issuecomment-460441229 >=20 > Greets, >=20 > Marco Pivetta >=20 > http://twitter.com/Ocramius >=20 > http://ocramius.github.com/ >=20 >=20 > On Mon, Jul 6, 2020 at 4:17 PM Josh Bruce wrote: >=20 >> Apologies, first time, still learning and have no historical context = - >> timing is what it is. >>=20 >> Proposal type: Concept >>=20 >> Implementer: Unknown, fallback to me after slow learning >>=20 >> Presumed simple implementation as the pattern should already be in = place: >>=20 >> Cast of (string) -> __toString() - already implemented >>=20 >> Cast of (bool) -> __toBool() >>=20 >> Cast of (int) -> __toInt() >>=20 >> Cast of (object) -> __toObject() >>=20 >> =E2=80=A6and so on. >>=20 >> Alternative implementation using an interface: >>=20 >> \CastableTo{type} >>=20 >> Extreme implementation: >>=20 >> Make both of the previous available. >>=20 >> Known unknowns: >>=20 >> - Level of interest in something like this in the PHP community = outside of >> one upvote on a Stackoverflow question I submitted: >> = https://stackoverflow.com/questions/62747837/php-7-tostring-or-other-inter= face-for-boolean-values >> < >> = https://stackoverflow.com/questions/62747837/php-7-tostring-or-other-inter= face-for-boolean-values >>>=20 >> - Whether this conversation or proposal has already occurred. >> - The historical conversation leading to the creation of the = __toString() >> method (and stopping there). >> - The current conversation around using magic methods in general and >> specifically when defining a cast response. >> - Enough details on PHP internal development to implement myself = (this is >> the first time in 20 years I felt I couldn=E2=80=99t comfortably = accomplish what I >> wanted to, thanks for that). >> - What potential collisions could occur if someone (me) wanted to >> implement all possibilities in a single class. >> - Right now __toBool() would be of the most personal benefit - if = proposal >> is converted to an RFC, would it be better (faster/smoother) to do = one RFC >> for all the cast possibilities - or to have an RFC for each cast = separately? >>=20 >> Thank you for the consideration, information, and feedback. >>=20 >> Cheers, >> Josh >>=20 >> ps. Also, apologies again for walking into a new space on a mission, = not >> my normal approach. >>=20 >> pps. The primary project inspiring the proposal: >> https://github.com/8fold/php-shoop = >>=20 >>=20 >>=20 Thank you for the reply Marco. Decided to put something together: = https://github.com/joshbruce/external-project-proposals/blob/master/php-co= ncepts/interact-with-instance-as-php.md = I really appreciated the links to and conversations on __toArray. I hope = I adequately incorporated and differentiated the desired outcome = (interact as if PHP primitive) instead of focusing on the implementation = (cast). Also, just to make sure I caught what you were saying: You recommend = avoiding making thing =E2=80=9Ccast-able=E2=80=9D - but ardently = necessarily opposed to other means. Cheers, Josh --Apple-Mail=_C49E08D3-611E-4A39-8625-AB4E3D73F449--