The downvotes will pour in because this is considered base level OOP knowledge, so if you struggle with this you might want to consider reading into OOP more.
I suggest the following:
https://code.tutsplus.com/tutorials/object-oriented-php-for-beginners--net-12762
https://www.tutorialspoint.com/php/php_object_oriented.htm
As for your question:
These parameters are important for inheritance and what you can use inside and outside of a class.
private
is the most enclosed setting, whereby you can not access or interact with anything (method or variable) that is marked private. Try creating a class with a dummy function which echoes out something. If you call this function from within the class, lets say in the constructor (using $this->myfunc()
notation), it will echo out as desired. But if you initialise the class and try to call the same function using the arrow notation ($myclass = new Myclass(); $myclass->myfunc();
) it will not work because you are trying to access a private member from outside.
protected
is the same concept but you can access protected members from child classes (look into child classes and inheritance if you're unsure, this is outside the scope of this question)
public
however is you may access it outside or inside the class.
As for a rule of thumb, I usually make anything private (unless there is further inheritance) that I know I don't want to or shouldnt have to call from outside. Anything else can be public. For example a lot of code I write will include having to write a base class which does a certain, extended procedure, for example cloning a github repo and updating files with it across our servers. Anything that is the part of this process (the function of cloning, the function of accessing a certain location, etc) are made private
because they are part of a workflow which should never have to be called on their own (there are exceptions of course, but this is a matter of practise). But if i have helpers, let's say to see if the github repo is accessible or not, I might as well make that public because a condition of whether or not we want to start the update process might be to first determine if the repo is accessible to me. This is of course not a very good example but I hope it helps.