PHP OOP Question

Reply

Join Date: Dec 2004
Posts: 234
Reputation: cancer10 is an unknown quantity at this point 
Solved Threads: 0
cancer10's Avatar
cancer10 cancer10 is offline Offline
Posting Whiz in Training

PHP OOP Question

 
0
  #1
Feb 4th, 2008
Hi,


I am new to PHP oop. I was wondering when and why should we use the following:

1) Public
2) Protected
3) Private
4) are there any other???


An example would be appreciated.



Thanx
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: PHP OOP Question

 
0
  #2
Feb 4th, 2008
Take a look at this .
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 57
Reputation: Walkere is an unknown quantity at this point 
Solved Threads: 5
Walkere Walkere is offline Offline
Junior Poster in Training

Re: PHP OOP Question

 
0
  #3
Feb 4th, 2008
Originally Posted by cancer10 View Post
I am new to PHP oop. I was wondering when and why should we use the following:

1) Public
2) Protected
3) Private
4) are there any other???
The link that Naveen posted has a good overview of these OOP concepts.

No, there are no other types - just these three.

As for when to use them... you should always try to use the most restrictive definition for a variable/function. This is an OOP "best practice," and helps ensure your code is easier to maintain in the long run.

As a general rule of thumb, variables should be private or protected - depending on whether inherited classes will be able to access them directly. There are very few variables that should be public - instead, you should write public functions to fetch and change them.

Methods should be public if (and only if) they need to be called from the main script. If they're called from other methods of the class, then they should be private or protected.

- Walkere
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC