Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92134 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29932 invoked from network); 7 Apr 2016 17:35:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Apr 2016 17:35:34 -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 212.232.28.124 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 212.232.28.124 mx203.easyname.com Received: from [212.232.28.124] ([212.232.28.124:36605] helo=mx203.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B5/60-48788-46A96075 for ; Thu, 07 Apr 2016 13:35:33 -0400 Received: from cable-81-173-133-226.netcologne.de ([81.173.133.226] 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 1aoDq5-0003R9-LS for internals@lists.php.net; Thu, 07 Apr 2016 17:35:29 +0000 Reply-To: internals@lists.php.net References: To: internals@lists.php.net Message-ID: <57069A49.2030806@fleshgrinder.com> Date: Thu, 7 Apr 2016 19:35:05 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="4AhvaGRBX2soHCOQtFOSPdoUqdtRrHrNN" X-ACL-Warn: X-DNSBL-BARRACUDACENTRAL Subject: Re: [PHP-DEV] Final properties From: php@fleshgrinder.com (Fleshgrinder) --4AhvaGRBX2soHCOQtFOSPdoUqdtRrHrNN Content-Type: multipart/mixed; boundary="nurC9ACan8Ij5ejjs5QXXoV5H1Lsk43fG" From: Fleshgrinder Reply-To: internals@lists.php.net To: internals@lists.php.net Message-ID: <57069A49.2030806@fleshgrinder.com> Subject: Re: [PHP-DEV] Final properties References: In-Reply-To: --nurC9ACan8Ij5ejjs5QXXoV5H1Lsk43fG Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable /Sending this again because the mail server was down./ +1 from my side too for this proposal. Retrofitting immutability with additional keywords is not the nicest thing but PHP has no other way (same was true for Java when they added it). Using the *final* keyword while subclasses are able to override it is ambiguous in PHP because it already has the notion that something is not extensible (class) or overridable (method). Hence, I would either use a different keyword or implement two keywords (and two RFCs): 1. *immutable* for the functionality you are currently working on. 2. *sealed* for the above plus type not changeable. 3. *final* for the above plus not being overridable. Opening restrictions should be possible as with widening visibility in inheritance but making something more tight should not because it would violate the (implicit) interface of the parent class. In other words: OK =3D=3D immutable -> mutable sealed -> immutable sealed -> mutable Fatal Error =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D immutable -> sealed immutable -> final sealed -> final final -> immutable final -> sealed final -> mutable mutable -> immutable mutable -> sealed mutable -> final Of course it would be nice to have the possibility to disable these restrictions while creating fakes, mocks, ... in unit tests. Sadly that is a feature that we don't have at all in PHP; e.g.: final class ClassUnderTest {} mock class TestDouble extends ClassUnderTest {} I do not think that there should be anything that prevents this new feature to work nicely together with typed properties. Of course I could be wrong here but then again it might only require a few adoptions of that feature to work nicely. One thing is for sure, *immutable*, *sealed* and *final* would also disallow references (e.g. sorting of an array); which is a good thing. --=20 Richard "Fleshgrinder" Fussenegger --nurC9ACan8Ij5ejjs5QXXoV5H1Lsk43fG-- --4AhvaGRBX2soHCOQtFOSPdoUqdtRrHrNN 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 iQIcBAEBCAAGBQJXBppVAAoJEOKkKcqFPVVrC0UP/ArKMg7qo8WSRkQ5VwzvPzV5 5ilLEFZtqyGRPoCRF3LYpDhTny2MlFeOc44SyvEs+SSlTr7zq3ymBM8ddoJW2tDb eFBg3zWeYQCvcmuJ94hRvyxQMit0CoAl1pFedczNU/US34eP7EKJAIh1IL02GY1W MXPcdYiEdGDxMMRxr7A0zEPk9ivOeF8kHRgAcH0cUijuDMQjBgdJ6+PPXM5Ov5FN 6oKlbekLBsqlTWVwyp7F53r/cbIWM3gED3Wd52dasD4WOxVo830gRy6wJ1Hmt8Po wmRxJKPYcEmvvjBHI/FDjhR9xbcW/2j9s/XjahgV+86tc1fevyIcX2aWa6wOvs/r vrYsZBol+2Xed+s3fiArqSxoOabjbRNiHv681olRDJ1i6w1uWWVdMTDKfpEQLGjd +doyEBB59xr8ZkQlQhbx+y3+UbmTHPYv0BzgFxz8tz0p8+b2laJLv/V3Y2Gj3ByF PanXdw1OCKJFbeY2lo9stULjVSbK9Kul5HKXZs0os80heDkb0ZuFSAMyF22H+VQy kZQ6Rm4PRuMO4wSRUKGdqGL5/tOmvLvKA0FpalRoYghAOioWCoEDzkQWoujBDXGI ekDMgvOs0XRLmioZz3Gc9Ep5f+lOc8QrzhiOzsu60C7M4+f3+oqol9LuTXi7j96E IdX+8i+hCVKtrTF9kQqa =h+3N -----END PGP SIGNATURE----- --4AhvaGRBX2soHCOQtFOSPdoUqdtRrHrNN--