Sunday, 5 February 2017

oop - private methods and variables in PHP usage

I have been thinking about the usage of private variables and methods in php.



I am not going to talk about a class of car or anything like that. I want to talk about an own script.



What is the difference between using public or private for the programmer and the owner of the script.



if the script is a calculator, and I am the only one who will meinten the code in the future. when do I have to use private variables of methods. How this is going to change anything in the script?



Also, If it's about touching the variable ? if anyone tries to change the value, and he couldn't because of the private thing. He will go directly to change it using the setters ?



I need a good example that I can see private methods or variables have good benefits for programmer or the end user.



I was programming some scripts, and a guy told me to not use var in classes. I asked him why ? he said that you have to use public or private .. and asked why ?



Why to use setter if there is a way to change the variable directly?



Why to use getter if there is a way to change the variable directly?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...