Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95976 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17116 invoked from network); 13 Sep 2016 07:40:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Sep 2016 07:40:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=michal@brzuchalski.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=michal@brzuchalski.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain brzuchalski.com designates 188.165.245.118 as permitted sender) X-PHP-List-Original-Sender: michal@brzuchalski.com X-Host-Fingerprint: 188.165.245.118 ns220893.ip-188-165-245.eu Received: from [188.165.245.118] ([188.165.245.118:55301] helo=poczta.brzuchalski.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 30/89-60695-67DA7D75 for ; Tue, 13 Sep 2016 03:40:41 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id 716A4298423B for ; Tue, 13 Sep 2016 09:40:35 +0200 (CEST) Received: from poczta.brzuchalski.com ([127.0.0.1]) by localhost (poczta.brzuchalski.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id URYD01af1_t5 for ; Tue, 13 Sep 2016 09:40:31 +0200 (CEST) Received: from mail-qk0-f177.google.com (unknown [209.85.220.177]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id DE20D2984239 for ; Tue, 13 Sep 2016 09:40:29 +0200 (CEST) Received: by mail-qk0-f177.google.com with SMTP id t7so64189620qkh.2 for ; Tue, 13 Sep 2016 00:40:29 -0700 (PDT) X-Gm-Message-State: AE9vXwM21X0CI77ZyP9bpWY4lWlKWFkEAgDnmAdgTVZEppNRs0lxPdpShw9inM02IwsA4PzeOnRfuSc0QzKzwQ== X-Received: by 10.233.239.86 with SMTP id d83mr16846236qkg.170.1473752428898; Tue, 13 Sep 2016 00:40:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.200.53.28 with HTTP; Tue, 13 Sep 2016 00:40:27 -0700 (PDT) In-Reply-To: <8478e9f9-6f03-fc54-30f3-7ba27314f82b@fleshgrinder.com> References: <83fa661e-2d3d-6548-a506-fb969be31c0e@garfieldtech.com> <56acc1d9-f424-a460-59be-3a9a1a74b198@fleshgrinder.com> <95832b08-ee80-18c1-a3da-202eed51903e@fleshgrinder.com> <2c115733-8fe4-5230-a9ec-9d5f2cc2b810@garfieldtech.com> <06ce2daf-4112-3464-b6d6-47f1ece05303@garfieldtech.com> <8478e9f9-6f03-fc54-30f3-7ba27314f82b@fleshgrinder.com> Date: Tue, 13 Sep 2016 09:40:27 +0200 X-Gmail-Original-Message-ID: Message-ID: To: PHP Internals List Cc: Larry Garfield Content-Type: multipart/alternative; boundary=94eb2c03e28a02f318053c5ebae6 Subject: Re: [PHP-DEV] RFC - Immutable classes From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --94eb2c03e28a02f318053c5ebae6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Proposed operator overloading and magic methods to compare with other objects is very good idea, I like it a lot, there even may be additional restriction provided with my other RFC https://wiki.php.net/rfc/object-typehint But I think this goal should be provided in separate RFC as it is very usefull in immutable objects, but also will be in mutable objects. While this is not required to introduce immutable objects I thinkk it should be in separate RFC. 2016-09-13 8:40 GMT+02:00 Fleshgrinder : > Thanks a lot for your feedback. > > I like the clone idea too and I also see no harm in allowing them in any > context rather than only in immutable classes. I am really against the > transformer keyword, don't ask me why, I just don't like it at all. :P > > I mentioned before that PHP should allow for operator overloading since > there are other value object use cases that are even simpler than your > HTTP header result: any value object that is case insensitive. Doh! > > I do like the https://wiki.php.net/rfc/comparable RFC but we would need > more for value objects to be truly useful. > > class A { > > // $this =3D=3D $other > function __isEqual($other); > > // $this =3D=3D=3D $other > function __isIdentical($other); > > } > > This will be very hard to get through though because it's operator > overloading. I am currently already doing this in many of my value > objects, although I usually implement an equals method only and let it > take care of equals and identity checks at the same time. > > final class HexNumber { > > private $val; > > public function __construct(string $hex) { > $this->val =3D strtolower($hex); > } > > public function equals($other) { > if ($other instanceof self) { > return $other->val =3D=3D=3D $this->val; > } > > if (is_string($other)) { > return strtolower($other) =3D=3D=3D $this->val; > } > > return false; > } > > } > > $hn =3D new HexNumber('ff00'); > var_dump($hn->equals('FF00')); // bool(true) > > However, this is not necessarily exactly what you want in every context, > hence, the proposal for operator overloading. > > That being said, I agree that this could (and probably should) be > tackled in another RFC. Immutable classes do not have to solve every > problem. > > -- > Richard "Fleshgrinder" Fussenegger > > --=20 regards / pozdrawiam, -- Micha=C5=82 Brzuchalski brzuchalski.com --94eb2c03e28a02f318053c5ebae6--