Is this a reasonable way to handle getters/setters in a PHP class?

前端 未结 8 1276
無奈伤痛
無奈伤痛 2020-12-16 03:50

I\'m going to try something with the format of this question and I\'m very open to suggestions about a better way to handle it.

I didn\'t want to just dump a bunch o

8条回答
  •  庸人自扰
    2020-12-16 04:14

    I can't help putting in my 2 cents...

    I have taken to using __get and __set in this manor http://gist.github.com/351387 (similar to the way that doctrine does it), then only ever accessing the properties via the $obj->var in an outside of the class. That way you can override functionality as needed instead of making a huge __get or __set function, or overriding __get and __set in the child classes.

提交回复
热议问题