Re: PHP5 newbie question (i hope) .. using inherited methods from a subclass
- From: bizt <bissatch@xxxxxxxxxxx>
- Date: Fri, 30 Nov 2007 04:41:34 -0800 (PST)
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.
.
- References:
- Prev by Date: Re: SQLite PDO numRows problem
- Next by Date: Re: Joomla?
- Previous by thread: Re: PHP5 newbie question (i hope) .. using inherited methods from a subclass
- Next by thread: php mail() not sending to mail Clients (ie, Outlook, Apple Mail, thunderbird, etc..)
- Index(es):