Re: php 5 classes: public, protected and private



jopperdepopper wrote:
Hi,

finally giving php 5 a go, and going over the new approach to classes.
Can someone clarify the public, private and protected to me?

I quote the php manual: "The visibility of a property or method can be
defined by prefixing the declaration with the keywords: public,
protected or private. Public declared items can be accessed
everywhere."

But should I read "...can be accessed everywhere within a given class."
or "...can be accessed by all other classes." ?

Job


Job,

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.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • php 5 classes: public, protected and private
    ... finally giving php 5 a go, and going over the new approach to classes. ... private and protected to me? ... I quote the php manual: "The visibility of a property or method can be ... Public declared items can be accessed ...
    (comp.lang.php)
  • Re: Magazine article
    ... websites. ... intended for private circulation among members of the ... and supplying information privately to family members. ... family members aren't family historians, ...
    (soc.genealogy.britain)
  • Re: Method of Unit Testing Private Methods
    ... > into the problem of how to properly unit test private methods of a ... I follow the philosophy that, if it's private, then its none of my ... members, via the correctness of the public members that use those ... Private Sub Foo() ...
    (comp.programming)
  • Re: (Probably) easy question about inheritance
    ... Typically a matrix uses a two-dimensional array, so it would be private ... I would like to access three data members: ... public inheritance is the same thing as inheritance in Java) ...
    (comp.lang.java.programmer)
  • Re: How To(?): Small Genealogy Groups
    ... > wanted to tell those stories, which were common to all of us, and even ... Most of the members, by the way, were ... I suspect that you could set up a private discussion group (as per this ... have precisely the same as yours are your siblings, ...
    (soc.genealogy.jewish)