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".

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

  • 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 :) – Ronen Ness Mar 31 '16 at 9:44
  • For other helpers beside the data helper I don't see any reason to inherit from the abstract helper – Fabian Schmengler Mar 31 '16 at 11:22
  • but do you see a reason not to? that's the question.. :) – Ronen Ness Mar 31 '16 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. – Fabian Schmengler Apr 1 '16 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 – Sander Mangel Apr 2 '16 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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