On Wed, Mar 9, 2011 at 3:23 PM, Chad Fulton <chadful...@gmail.com> wrote:

> Hello,
>
> On Wed, Mar 9, 2011 at 10:02 AM, Jarrod Nettles <jnett...@inccrra.org>
> wrote:
> > Interesting question. My gut tells me not (as does three years of C#
> experience). I’m sure that everyone will have a different opinion on this
> but to me it seems taboo that a child class override the visibility of the
> parent class. For example, PHP currently does not allow you to override a
> method with a lower or higher visibility than the parent – I can’t go from
> protected to public or vice versa. Visibility must be maintained throughout
> the class hierarchy.
> >
>
> Actually, class properties and methods can have a higher visibility
> than their parents, just not a lower one.
>
> E.g.:
>
> <?php
>
> error_reporting(E_ALL | E_STRICT);
>
> class foo {
>    protected function bar() {
>
>    }
> }
>
> class baz extends foo {
>    public function bar() {
>
>    }
> }
>
> class foobar extends baz {
>    protected function bar () {
>
>    }
> }
>
> ?>
>
> You get the following error:
>
> Fatal error: Access level to foobar::bar() must be public (as in class
> baz) in ...
>
> -------
>
> That said, I wouldn't think that visibility modifiers on classes need
> to follow the same pattern. In the case of properties and methods, I
> think the rationale is that child classes should be compatible from an
> interface standpoint with their parents. That same logic may not
> transfer to class visibility modifiers.
>

yes, every class should specify its own visibility.
Inheritance here does not make any sense, you only will be able to use
private classes at the cost of your entire class hierarchy being private too
.




>
> I am certainly no expert, but I'm curious what the use case is for
> class visibility modifiers?
>
> On Wed, Mar 9, 2011 at 7:11 AM, Hannes Landeholm <landeh...@gmail.com>
> wrote:
> > Currently I'm forced to use huge internal classes for my framework
> because
> dividing them into smaller classes would expose internal behavior to the
> "outside"... the application layer.
> >
>
> This doesn't necessarily make sense to me. Isn't it the
> end-developer's problem if they start instantiating classes in weird
> ways?
>

Well, that depends on who is your end-user?
Current object model works well for small-to-mid size application, but it
does not allows to write *safe* libraries

safe: to don't break client code, because of wrong client code.


> It doesn't seem the same as having a private method, since in that
> case the end-developer presumably already has an object instance, and
> you want to guide them to the correct interface for interacting with
> it, whereas in an application, one would think that the end-developer
> wouldn't simply be instantiating classes by themselves all over the
> place.
>
> Chad
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to