Getter and Setter?

前端 未结 15 665
南方客
南方客 2020-11-22 16:47

I\'m not a PHP developer, so I\'m wondering if in PHP is more popular to use explicit getter/setters, in a pure OOP style, with private fields (the way I like):



        
15条回答
  •  感情败类
    2020-11-22 17:28

    Why use getters and setters?

    1. Scalability: It's easier refactor a getter than search all the var assignments in a project code.
    2. Debugging: You can put breakpoints at setters and getters.
    3. Cleaner: Magic functions are not good solution for writting less, your IDE will not suggest the code. Better use templates for fast-writting getters.

    direct assignment and getters/setters

提交回复
热议问题