I am using magento 1.8
And I am facing problem when I use below methods
$product->getData('name');
$product->getName();
Is they are same,
I sure that they return same value[answer].
When I am using I am getting error
Fatal error: Call to a member function getData() on a non-object in
So may i know the exact difference between these two function.
Thank You,
Best Answer
They may be the same or they may be different. It depends on the object you are using.
If the class you instantiate contains the method
getName()
then the result you get fromgetName
andgetData('name')
may be different.You can even get an error if the class does not extend
Varien_Object
and does not have the methodgetData
.For classes that extend
Varien_Object
and do not contain the methodgetName()
the results of the 2 methods are the same.Varien_Object
implements the method__call
that is called if a certain method does not exist. See here how the code looks like.So it basically maps the call of any method
getSomethingHere()
togetData('something_here')
. It works the same for "fake" methods that start withset
,has
anduns
.More details provided here.