7

I heard conflicts opinions about weather or not one should only inherit from Mage_Core_Helper_Abstract, even when none of the helper built-ins are used.

So if I have couple of helper classes that I get using the magento Mage::helper() api, but those helpers don't use anything from Mage_Core_Helper_Abstract, should I still inherit from it?

My tendency goes with yes for good practice, but maybe there are performance / resources waste involved that I'm not aware of.

Thoughts?

EDIT: I saw examples in Magento code of helpers that inherit from helper abstract without using its functions (http://freegento.com/doc/d3/d82/_helper_2_string_8php-source.html). So unless someone gives me a good reason why I shouldn't do it, I think I'll go with "always inherit from helper abstract".

1 Answer 1

14

Magento relies on the data helper in a module for a lot of 'automatic' translation stuff like the labels in the system.xml for example.

This translation functionality is only available after extending Mage_Core_Helper_Abstract.

So I'd say it's not required but it's a good practice to do so and prevents issues in the future when you do rely on translations in your module

5
  • I think so too but I heard an experienced magento dev saying not to needlessly inherit from it (unfortunately without explaining why) and it made me wonder. You reinforced my natural tendency so I'll go with your way. Just to be clear though - I'm not talking about the default data helper, I'm talking about customized random helpers I create for my modules. If that somehow change your answer let me know :) Commented Mar 31, 2016 at 9:44
  • For other helpers beside the data helper I don't see any reason to inherit from the abstract helper Commented Mar 31, 2016 at 11:22
  • but do you see a reason not to? that's the question.. :) Commented Mar 31, 2016 at 11:47
  • Yes, that it's unnecessary. Why would you want to add code that you don't use? And a practical reason: IDE autocompletion. You only want to see the relevant methods there. Commented Apr 1, 2016 at 20:42
  • hm I think I agree with @fschmengler here. Except for data you probably don't want to extends the abstract class. Unless there is an explicit reason to do so Commented Apr 2, 2016 at 7:04

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.