Re: php 5 classes: public, protected and private
- From: "Tony Marston" <tony@xxxxxxxxxxxxxxxxxx>
- Date: Mon, 27 Nov 2006 23:32:24 -0000
"Jerry Stuckle" <jstucklex@xxxxxxxxxxxxx> wrote in message
news:Ib6dna_BtYQSifbYnZ2dnUVZ_sSdnZ2d@xxxxxxxxxxxxxx
jopperdepopper wrote:
You should read "can be accessed everywhere".
Private members can be accessed by members of the class only.
Protected members can be accessed by members of the class or a derived
class.
Public members can be accessed by anyone, including other classes,
functions and any other code.
Thanks Jerry. I'm trying to make a bit of sense of the php 5 approach
to classes, and so far having a hard time. I fail to see the 'why'
behind the 'public, protected and private' and stuff like abstraction,
interfaces and whatnot.
Intefaces are not necessary in PHP. Once you have defined a method it is a
total waste to time to also define an interface. Interfaces are a "fix" in
those languages as a means of dealing with optional arguments and statyic
typing. PHP has ifferent ways of dealing with bth of these, therefore
interfaces serve no useful purpose.
Feels like things are being over-complicated
somehow... or it's just my being inexperienced on this...
Any other reading material on this suggested, someone?
Look for some good books on OO theory and design.
Two of the concepts in OO are 'encapsulation' and 'methods'.
Encapsulation means the internals of an object are managed only by that
object and are not available to anyone else. In PHP these are private
members.
Wrong. Encapsulation means that the data and the functions which operate on
that data are contained (encapsulated) within a single object. While the
methods (functions) thenselves may be visible the code behind those methods
(i.e. the implementaton behind those methods) is not. Encapslation is NOT
about hiding information, it is about hiding the implementation. It is not
necessary to use public/private/protected on any methods or properties. It
does not add any functionality, it merely creates restrictions which often
get in the way.
Methods are implemented as functions in PHP. They operate on the object.
That's one thing you got right.
--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
.
- Follow-Ups:
- Re: php 5 classes: public, protected and private
- From: Jerry Stuckle
- Re: php 5 classes: public, protected and private
- From: Michael Fesser
- Re: php 5 classes: public, protected and private
- References:
- php 5 classes: public, protected and private
- From: jopperdepopper
- Re: php 5 classes: public, protected and private
- From: Jerry Stuckle
- Re: php 5 classes: public, protected and private
- From: jopperdepopper
- Re: php 5 classes: public, protected and private
- From: Jerry Stuckle
- php 5 classes: public, protected and private
- Prev by Date: Re: Portal Software - For PHP /MySql
- Next by Date: Re: xml beginner - hierarchies
- Previous by thread: Re: php 5 classes: public, protected and private
- Next by thread: Re: php 5 classes: public, protected and private
- Index(es):
Relevant Pages
|