Posted by bizt on 11/30/07 12:41
> What if you declare $newsID, $title, etc. as protected instead of
> private. Private visibility means that the method or property is only
> available from that class. Protected visibility means that it's
> available from anywhere in the inheritance hierarchy.
>
> This code demonstrates that the superclass can access protected
> members of a subclass:
>
> class Superclass {
>
> public function foo() {
> echo $this->bar;
> }
>
> }
>
> class Subclass extends Superclass {
> protected $bar = 'bar';
>
> public function bar() {
> $this->foo();
> }
>
> }
>
> $c = new Subclass();
> $c->bar();
>
> If I'm misunderstanding your problem let me know.
Yeh that seems to work fine thanks. I thought protected was declared
in the parent class but when inherited it would then be available to
the subclass. I need to properly understand visibility better i think,
I used objects in php4 and i done a little oop when at uni but this is
the first time ive really started to seriously start using proper oo.
[Back to original message]
|