Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95974 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8821 invoked from network); 13 Sep 2016 06:40:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Sep 2016 06:40:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 77.244.243.85 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 77.244.243.85 mx104.easyname.com Received: from [77.244.243.85] ([77.244.243.85:56578] helo=mx206.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3F/08-60695-46F97D75 for ; Tue, 13 Sep 2016 02:40:36 -0400 Received: from cable-81-173-132-21.netcologne.de ([81.173.132.21] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1bjhOS-000235-Au; Tue, 13 Sep 2016 06:40:32 +0000 Reply-To: internals@lists.php.net 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> To: Larry Garfield , internals@lists.php.net Message-ID: <8478e9f9-6f03-fc54-30f3-7ba27314f82b@fleshgrinder.com> Date: Tue, 13 Sep 2016 08:40:14 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <06ce2daf-4112-3464-b6d6-47f1ece05303@garfieldtech.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="VN7QaXXHFntfH6T1i2i0CiCCCpNIDpwM5" Subject: Re: [PHP-DEV] RFC - Immutable classes From: php@fleshgrinder.com (Fleshgrinder) --VN7QaXXHFntfH6T1i2i0CiCCCpNIDpwM5 Content-Type: multipart/mixed; boundary="6rU8Gj9XP7NDWUSvW5vpxr1Qro2wNa8kU"; protected-headers="v1" From: Fleshgrinder Reply-To: internals@lists.php.net To: Larry Garfield , internals@lists.php.net Message-ID: <8478e9f9-6f03-fc54-30f3-7ba27314f82b@fleshgrinder.com> Subject: Re: [PHP-DEV] RFC - Immutable classes References: <0800a5ca-3d14-c541-1a1a-2574ec802b8c@fleshgrinder.com> <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> In-Reply-To: <06ce2daf-4112-3464-b6d6-47f1ece05303@garfieldtech.com> --6rU8Gj9XP7NDWUSvW5vpxr1Qro2wNa8kU Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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. --=20 Richard "Fleshgrinder" Fussenegger --6rU8Gj9XP7NDWUSvW5vpxr1Qro2wNa8kU-- --VN7QaXXHFntfH6T1i2i0CiCCCpNIDpwM5 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJX159YAAoJEOKkKcqFPVVrLxgQAMpiMm5pufkXB+5kFRgX3/Fz 9Fdzh21TUUYzEngu1cSRqeH/VeC6GOuo9GX9PlgbzzaoPhTMBBXMiT+VOVSNltqL hZ8WvgLgiWAhVfmAw+UBKeNmDc8Da01FI03nvAgIWvaXYcYxhEe5mZHHy536bQTe +XLOT3YdCz88nSF2OaVqz8uSCxQHPcep4sj50HmWAc4wMg1GR24iHBBSwwsolHwX v0U1L+NQyMzxVur8HXABi2Xd4FyAJi6sPrL6QKBQqJ3yipE9kvVftO0ftkVJM8if WzcKbqWqNccqMJWd8Pid5iVZqQIzMnPQPRPS+/HwT/gCFWloN4UZ3v9UI5EZJEtw 2QWTewyptKzOmeqZnVvZBbkteAfyNPiPKkIghc3pg7cZHPSgloljh7hLf6+H5vOD HgXldIPs2Z2/OF9FSV69BP5MJuFP42dXlWyMaIhEb3ga1lGHtDhNfLIkhoBO+nnC EATqe4JQViEPbgwuPqbSxkPt3k4HFlSgA9GO9RrhdNoGQahEQoDQ2e0uSQ4OLYl6 nTyQVn4lgz+4SyggpKflA7brMG+sDjpc1I0VBlK9jF5WaaJPzxyIqDJhba0ItZXw hHwWKZTqevucx/uJ3od3uDPDKrt9cyHLaTKQuWwbINdmqSZxzt5Hik1EriLEuKhq wTYXpQJhLU+XomLMSte7 =ld5e -----END PGP SIGNATURE----- --VN7QaXXHFntfH6T1i2i0CiCCCpNIDpwM5--