Hello,

On Dec 1, 2007 9:38 PM, Richard Quadling <[EMAIL PROTECTED]> wrote:

> On 01/12/2007, Jingcheng Zhang <[EMAIL PROTECTED]> wrote:
> > Well, yes, "private" denies accessing from other class(including its
> child
> > class), this is what "encapsulation" means. But when refering to
> > inheritance, why forbids private properties/methods being *extended* to
> > child classes? This is what I mean, as the following example:
> >
> > <?php
> > class p {
> >     protected $foo = 'foo';
> >     private   $bar = 'bar';
> > }
> > class c extends p {
> >     public function f() {
> >         $o = new p();
> >         $o->foo = 'FOO';    // Correct, "foo" is protected property of p
> and
> > thus allow accessing from child class
>
> This is not allowed. $o is in a different context (I think that's the
> right way of describing this) and as such has no access to the private
> or protected members of $o. Just because it $o is created within class
> c, it is not related.


Again, the context check is based on the class and not on the instance,
which is "correct" (same behavior in other OO languages like java, scala, or
C++)

I believe what he means is that private properties are simply masked,
allowing one
user to dynamically create an "overloaded" property, like:

class A {
   private $a;
}

class B extends A{
   private $a; // allowed, but I guess what he wants is to have that
optional
   public function foo() {
      $this->a = 3;
   }
}

Having this optional is a bad thing because:
1) it reduces the readability
2) the access type of the dynamically created B::$a would be ambiguous.

So, you should always explicitly define the overloaded property, and the
language shouldn't be modified to allow such concept.
Please take this to php_generals as this is not really the right place
anymore.

Regards



-- 
Etienne Kneuss
http://www.colder.ch

Men never do evil so completely and cheerfully as
when they do it from a religious conviction.
-- Pascal

Reply via email to