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
        $o->bar = 'BAR';    // Incorrect, "bar" is private property of
*class p* here
    }
    public function g() {
        $this->foo = 'FOO'; // Correct, "foo" is
        $this->bar = 'BAR'; // Should be OK, as "bar" is private property of
*class c* here
    }
}
?>

Thanks.


On Dec 1, 2007 12:57 AM, Johannes Schlüter <[EMAIL PROTECTED]> wrote:

> Hi,
>
> On Sat, 2007-12-01 at 00:24 +0800, "Jingcheng Zhang" wrote:
> > Hi Etienne,
> >   Is "private" only an access limiter between classes?If so, I think
> private
> > properties and methods should be OK to be extended into the child class,
> but
> > currently that's not the case, and there is also a bug here, consider
> the
> > following example:
>
> The child class is another class, "private" gives you encapsulation
> inside the base class's context. and preventing acces from other class's
> context.
>
> johannes
>
>


-- 
Best regards,
Jingcheng Zhang
Room 304, Dormitory 26 of Yuquan Campus, Zhejiang University
P.R.China

Reply via email to