On Sat, 19 Sep 2020, 09:20 Olle Härstedt, <olleharst...@gmail.com> wrote:
> > On Fri, 18 Sep 2020, 00:13 Mike Schinkel, <m...@newclarity.net> wrote: > >> >> >> > On Sep 17, 2020, at 8:28 AM, Olle Härstedt <olleharst...@gmail.com> >> wrote: >> > >> > (NB: This idea is NOT about namespace visibility for classes, >> interfaces or >> > traits (already discussed here: >> https://wiki.php.net/rfc/namespace-visibility). >> > It's about adding a *new* visibility qualifier, call it "internal", to >> > make properties >> > private inside a namespace. The purpose is to make composition less >> > fragile by not >> > exposing more than necessary.) >> > >> > (NB: This feature exists in Swift, described here: >> > https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html) >> > >> > We have public, protected and private. Since PHP has no module system, >> we >> > have no qualifier to mark a class property as "private for this module". >> > One solution to this could be to add a new qualifier "internal", to make >> > properties public within the current namespace. >> > >> > Use-cases: >> > >> > * Split data and behaviour into different files and classes >> > * Safely skip getters and setters without risk of properties being >> abused >> > by client code >> >> +1 >> >> This might be able to address a use-case I have wanted for a while, which >> is to have traits with properties (and methods) that are not accessible >> with the class that uses the trait. >> >> So if a trait is in a different namespace than the using class, the using >> class would not be able to access these "internal" properties. >> >> Or at least I think that could work? >> >> -Mike >> > > True, the properties/methods of the trait could be made internal, while > exposing the trait itself (and at least one method, to make it usable). > > The question is if PHP tracks the current namespace it's in on each line. > It needs to be known at all times for such an access level to work. > > Olle > Just discovered that this feature already exists in Psalm, @psalm-internal. They are streets ahead. :) Olle >