> > -- Matthew Ratzloff <matt@builtfromsource.com> wrote
> > (on Wednesday, 03 June 2009, 11:16 AM -0700):
>> >> Using __get() and __set() for properties known at the time of
writing is a
>> >> minor time saver for you, the programmer, and can be a major time
waster for
>> >> those trying to debug or otherwise understand your code. It's a
bad practice.
> >
> > I disagree, and feel it's a documentation issue.
I disagree, and think it depends on your development mantra.
Two major issues come to my mind:
1) Unit tests
2) Code completion in IDE
You cannot really test objects with magic methods, because PHP stops
emitting hard errors when trying to access undefined methods or
properties. Those errors would normally stop you from trying something
inappropriate with the object. Omitting those errors might result in
hours of debugging.
If the methods and properties are not enumerated in the code, but result
from the correct execution of code, no code completion logic can work.
Bad thing.
> > Doing so can often make a class forward-compatible with future versions
> > by ensuring uniform accessors and properties tied to accessors from the
> > start. You may not need them immediately, but you may in future
> > iterations, and adding them later would be a BC break and/or require
> > adding __set and __get anyways, but now with more complex logic.
YAGNI! :)
Regards,
Sven
没有评论:
发表评论