You are here: Re: PHP5 newbie question (i hope) .. using inherited methods from a subclass « PHP Programming Language « IT news, forums, messages
Re: PHP5 newbie question (i hope) .. using inherited methods from a subclass

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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация