I am learning php oop. But I can not understand in which situations use public, private and protected. I know that public is accessable inside the class and outside the class, protected inside the class and inside classes which inherites it, private is accessable only inside the class. But how to know that the property or method must be protected or private ? I know that if write class for connecting database they must be protected or private. But, an example: I am writing registrating class(is the code below true ?):
private $email;
private $username;
private $password;
private $securitycode;
private function register {
//here registrations codes, may be I must use public function ?
}
Another example: I have news section in the website and want to get news details (id, title, text, author) and write News class (is given code below true ?):
private $id;
private $title;
private $text;
private $author;
public function get_one_news($this->id) {
//here the code for getting the news, may be I must use protected function ?
}
Another example: I want to get number of users or news: Which I have to use : public, protected or private function ? Another example: Every user(registered or unregistered) can add comment(id, comment): Can I use public $id; public $comment ? or I have to use protected or private ?
Please, I need your advices. Which(public, protected, private properties and functions) to use if I want to add/get news, to register/login user, to add/edit/get data from database tables, to make fileuploading and etc. ? I could not find answers to my question.