F
F
Friend2021-06-25 23:24:44
OOP
Friend, 2021-06-25 23:24:44

Is it always good or bad to use Getters and Setters?

I am developing on PHP. More and more I switch towards OOP.
Now the question has been asked. There are class variables - there are usually a lot of them.
How to access them from class methods? directly or through getters?
and the same thing how to set them values? directly or via setters? let's say there is a private $filename

variable ; In the constructor, its value is passed in the body of the constructor, I write $this->filename = $filename; and when in other functions of the class it is necessary to get the name, I use the getter $this->getFilename() Or is it already a search and inside the class you can directly receive and write to your variables? Please brainwash me on this subject.







Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DollyPapper, 2021-06-26
@Utarzan123

Within the class itself, you can access properties directly. From the outside, it's better to do it through getters and setters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question