I'm opening this issue to discuss how are should use __set and __get (same should be applicable to __isset and __unset) like any lazy developer I used to like magic methods and I used them a lot to avoid boilerplate code and to reduce maintenance. They are nice when writing code but not nice when reading code from others.
They have some negative points:
- Resulting code is not as readable as normal function names
- Interfaces like $obj->attr when you know you are not dealing with a stdClass are confusing; they are not straight forward to deprecate and, may result in future conflicts if we change the class interface. This is worst when they are public interfaces as we need to maintain backwards compatibility
- Not ideal during development: IDE autocompletion not working, shared php-doc block... (this last point might be considered good though)
- Slower than normal functions, depending on where they are implemented the difference is significant, I don't think we should use the premature optimisation thing as an excuse here. Performance comparison: http://www.garfieldtech.com/blog/benchmarking-magic
As examples of this we have modinfolib, where we abuse the functionality and results in a significant performance impact as it is a widely used lib in some components.
- has been marked as being related by
-
MDL-53213 Make databasemeta cache a simpledata cache and improve performance
- Closed