Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91778 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26640 invoked from network); 19 Mar 2016 12:43:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Mar 2016 12:43:36 -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:40526] helo=mx203.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 96/F8-03097-6794DE65 for ; Sat, 19 Mar 2016 07:43:35 -0500 Received: from cable-81-173-135-2.netcologne.de ([81.173.135.2] 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 1ahGE6-00048a-Uu; Sat, 19 Mar 2016 12:43:31 +0000 Reply-To: internals@lists.php.net To: php-internals , =?UTF-8?Q?Bj=c3=b6rn_Larsson?= Message-ID: <56ED495C.80809@fleshgrinder.com> Date: Sat, 19 Mar 2016 13:43:08 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="3wlMKiHEWOtBETQ9RhA6m3aXbSjfN7nMl" X-ACL-Warn: X-DNSBL-BARRACUDACENTRAL Subject: Access and Visibility Modifiers From: php@fleshgrinder.com (Fleshgrinder) --3wlMKiHEWOtBETQ9RhA6m3aXbSjfN7nMl Content-Type: multipart/mixed; boundary="lnEqsaoGHxGSCN4VbeGGW1vBAF9XGd1uM" From: Fleshgrinder Reply-To: internals@lists.php.net To: php-internals , =?UTF-8?Q?Bj=c3=b6rn_Larsson?= Message-ID: <56ED495C.80809@fleshgrinder.com> Subject: Access and Visibility Modifiers --lnEqsaoGHxGSCN4VbeGGW1vBAF9XGd1uM Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 3/19/2016 12:51 PM, Fleshgrinder wrote: > Moving this to a new thread in order to not spam the other. > > On 3/19/2016 11:48 AM, Fleshgrinder wrote: >> On 3/19/2016 11:38 AM, Bj=C3=B6rn Larsson wrote: >>> Den 2016-03-18 kl. 21:12, skrev Fleshgrinder: >>>> No worries you are not, not at all. I just wanted to thwart you and >>>> others in directly assigning ... >>>> >>>> final class A { >>>> int $x; >>>> } >>>> >>>> ... to be *public* and obstruct the opportunity of assigning it a >>>> meaningful new functionality. >>>> >>> Well, but if one should assign int $x without visibility keyword a >>> meaning, shouldn't it be the same as for function y() {} without >>> keyword, i.e. public? >>> >>> Of course one can change both, but that sounds like a 8.0 topic. >>> >>> Regards //Bj=C3=B6rn >>> >>> >> >> It is a sad state the implicit public properties use *var* and implici= t >> public methods nothing, this makes the introduction of new visibility >> modifiers terribly complicated. You are completely right, they should = be >> the same and *var* should be banned. It is consistent and that is very= >> important. I cannot and do not want to argue against this. Yet at the >> same time the lack of access (and additional visibility) modifiers is >> what I am missing the most. Seems as if this has to wait for 8.0 (or >> 9.0, depending on the resistance). :( >> > > I just thought about this some more and this is actually not true. > > namespace Fleshgrinder\Examples\PhpInternals; > > final class A { > int $x; > var $y; > $z; > > function getX() { > return $this->x; > } > } > > Everything is public here, as we already agreed upon and changing that > would be a topic for 8.0 or 9.0. The *var* keyword should be banned imh= o > but I do not know about the *$z* in the example. Is this even possible > with the parser? Otherwise we could keep the *var* keyword because with= > my proposal here it would become useful again. > > assembly fleshgrinder/experiments; > > namespace Fleshgrinder\Examples\PhpInternals; > > final class A { > int $x; > > function getX() { > return $this->x; > } > } > > Where *assembly* could also be *module*, *package*, ... and it allows > one to group multiple classes and namespaces together across composer > packages. Furthermore it alters the access and visibility of members. I= n > the above example where no visibility modifiers are specified both the > class /A/ and the method /getX/ are only accessible within the > *fleshgrinder/experiments* assembly. This approach would allow the > introduction of such a system in a feature release (7.x.0) without > breaking changes. Either the new keyword is present and missing > visibility modifiers are globally scoped (hence implicit public) due to= > everything being in the global assembly by default or the new keyword i= s > present and missing visibility modifiers are restricting access to the > assembly. > > Usage of the word /package/ could be a blessing and a curse at the same= > time because the word is already heavily in use in the PHP world, e.g. > /@package/ in DocBlocks or in /composer package/. > > The same holds true for /module/ because it is sometimes used to refer > to PHP extensions and PEAR uses it. > > Hence, *assembly* might be the best choice here and is my proposal. > > The following proposal in regards to access and visibility is not well > thought through but hopefully a starting point: > > # Methods > private :=3D limited to the current class > protected :=3D limited to the current and child classes > :=3D limited to the current assembly > public :=3D global > > # Properties > private :=3D limited to the current class > protected :=3D limited to the current and child classes > :=3D limited to the current assembly > public :=3D global > var :=3D E_STRICT or limited to the current assembly > > # Classes, Interfaces, and Traits > private :=3D limited to the current namespace > protected :=3D limited to the current and child namespaces > :=3D limited to the current assembly > public :=3D global > > Default assembly is always global and old code would not change at all.= :) > Reposting to make sure that this is a new thread. --=20 Richard "Fleshgrinder" Fussenegger --lnEqsaoGHxGSCN4VbeGGW1vBAF9XGd1uM-- --3wlMKiHEWOtBETQ9RhA6m3aXbSjfN7nMl 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 iQIcBAEBCAAGBQJW7UliAAoJEOKkKcqFPVVrwwcP/3Qt81X0u/1EcOcOUfaY4M3R 27NbAP31UnLRRqtkgbjmQEj20p1XwYsTinXHcNOJwev5EVZxup7uuxlarEOrhtOX iE8TCrFq2VYCRmgTMfQsFAllZ8bOlvxKjwyylsKbmyTvuc3/lFrQky+GgyMNKbnJ 9V1m96YRzWMj4ulW46m+OqBA1SYhav6rKXwpG8rTDsDXrL9v/JWq5MMNk49OKaPv LfhhV1ZnV9LZLWepud8YL+0dlYpIuiNCrDSPejg1UHLNJbR2bJy4IJpczQ8C5+21 736PlP9QWcOXFFwvsHi+bDDCROwcEmPSF+wQnWz1StcN8ja315SWYKZcPN1zCGbN pbSnddb13vdnX9Kp9SX4VaIDCuYBzwfrbs1oRTJWIfHjtcG23hxF41UJ/n2I0mp3 eAIZLQSbEw0eHQ/o1uF6XrLqFpQI0dJl8MYQ4VPzqnmS/qtJfw/7y6j/pvFRZSat PBpHMGQ5yFz4zivYa3+oYuNAn82BGRWiDD1MXuxkj2FjytsZKZ0hAeFMaAtM0SkB cCtLUgIvqzPuT5IecaFZDKOlu0ufTYMOhGdr8gGari8b2TjT/HsockOEi4y7M00r 6NfSSlk7nvtlJgTin1a1qwui8mrDaZSpqO9gkD8ivYLTfPv0Zg4tah2N3YfEk3xV mXxONgt7M0R+vaqVQZQF =mKn6 -----END PGP SIGNATURE----- --3wlMKiHEWOtBETQ9RhA6m3aXbSjfN7nMl--