Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using magento 1.8

And I am facing problem when I use below methods



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,

share|improve this question
up vote 10 down vote accepted

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 from getName and getData('name') may be different.
You can even get an error if the class does not extend Varien_Object and does not have the method getData.

For classes that extend Varien_Object and do not contain the method getName() 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() to getData('something_here'). It works the same for "fake" methods that start with set, has and uns.

More details provided here.

share|improve this answer
Good explain @Marius,i am give you upvote – Amit Bera Jun 13 '14 at 6:59
@AmitBera. Thanks. same for you from my side. – Marius Jun 13 '14 at 6:59
Thank you Marius, You helped me lot. Thank so much – Charlie Jun 13 '14 at 7:14


In most cases, this is the method you should use. Of the two options, this one is actually faster and more efficient. If you have no need to modify the output, and just want to display the value, use getData(). However, there are attributes that may not work properly with getData() such as the product price. Though I haven’t tested it yet, getData(‘name’) will most likely end up producing different results than getName().


You should really only use this method if you are needing to override the method in your block to add functionality to how the data is displayed/formatted. Magento needs to take some additional steps in rendering the data when you use this method, so it is a slightly slower process than displaying data using getData(). So, by using $_product->getName(), I am able to add a function to the product view block for example to modify the data before it is output to

Some details:

share|improve this answer
I always use the second method because you never know when someone else will want to make an override. It is an important part of collaborative working. – clockworkgeek Oct 18 '14 at 11:07
Can you please edit my answer – Amit Bera Oct 18 '14 at 11:13
I don't think it's necessary to change your answer as I was only adding my opinion. – clockworkgeek Oct 18 '14 at 11:15

protected by Amit Bera Sep 20 '14 at 1:44

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.