Re: Class Access Modifiers
| From: | James Butler | Date: | Wed, 09 Mar 2011 15:18:39 +0000 |
| Subject: | Re: Class Access Modifiers | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-51641@lists.php.net to get a copy of this message | ||
>> Proposal (after five minutes of thought)
>>
>>
>> 1. Public - A class can be instantiated or called statically from
>> anywhere. For reasons of backward compatibility a class without any modifier
>> would be considered public.
>>
>> 2. Internal - A class can only be instantiated/called from within the
>> same root namespace. If I have a class Core\Mvc\View, only from within a
>> class sharing the same root namespace (ex: Core\Html\Textbox) would I be
>> able to access the "View" class.
>>
>> 3. Private - A class can only be instantiated/called from within the
>> exact same namespace. Example, class Core\Mvc\View could only be accessed
>> from a class in the Core\Mvc namespace (ex: Core\Mvc\Controller).
>>
>> What do people think? I'm not too concerned with the exact three I listed
>> above, but more and more I think it would be wise if there were a way to
>> restrict the accessibility of classes between namespaces.
>>
>> Jarrod Nettles
>>
Really like the general idea and think (IMHO) its RFC worthy, but have a
few questions...
Would there be any method of overriding the the visibility in a child
class?And would the child class inherit the parents visibility?
I realise this may seem daft initially but I can think of some instances
where this might be useful.
James