> 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

> 
> Tiny example:
> 
> ```
> namespace App\User;
> class User {
>  internal $username;
>  internal $password;
> }
> 
> namespace App\User\Services;
> class ProcessUser {
>  // Child namespace has access to internal properties,
>  // but App\ has not.
> }
> ```
> 
> Possible?
> 
> Olle
> 

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to