I have been using magento for a while now and always cant decide between using the magic getter and getData()
Can someone explain the main difference, apart from the slight performance overhead (and it must be very slight).
I am thinking in terms:
- Future code proof (i think magento 2 will not be using magic getter)
- Stylistically
- Performance
- Stability
- Any other reasons to use 1 over the other
There is no clear way to go based on the core code as it uses a mixture of both
In my opinion, the safest way is to always use
getData($key). The magic getter uses the same method as you already pointed out.The advantage is that you can find all references to getData in your code and change it appropriately in case the
getData()method is refactored. Compare that with having to find out all magic method calls where they are always named differently.The second thing is that the magic getter can screw you up easily when you have a method which is named the same way (I think getName() got me once and it took quite some time to debug).
So my vote is definitely for using
getData().