Is it really that wrong not using setters and getters?

前端 未结 7 896
谎友^
谎友^ 2020-12-03 07:51

I\'m kind of new in PHP. For some reason in other types of programming languages like JAVA I have no problem with using setters and getters for every single variable, but wh

相关标签:
7条回答
  • 2020-12-03 08:43

    If you access these variable in your script lots of time and if you update yoru class often you should use setters and getter because but if you dont this , when you improve your class you have to update all files which uses this variable .

    Secondly main reason why you do this is you should not access variable directly because class structure may change and this data can be providen differently.While you are getting data from class you should not care about how this data is generated .Class have to care about this data proccessing so you only should care what will you get.

    0 讨论(0)
提交回复
热议问题