1

Is a good practice to instantiate a Magento help in the class constructor?

protected $helper 

public function __construct()
{
    $this->helper=Mage::helper('helper_name');
}
0

1 Answer 1

1

Magentos helpers are always singletons, so it's not necessary to instantiate them. Just using Mage::helper('helper_name')->someMethod() should be OK.

3
  • tnx, in terms of code readability I'd like to use $this->helper. Any contraindications with my code?
    – apedic
    Commented Aug 7, 2017 at 13:59
  • Imho, no, but i try to avoid such things :) How about an wrapper method _getHelper() { return Mage::helper ...} and using $this->_getHelper() (it's not much longer)? Maybe wait for another answer?
    – sv3n
    Commented Aug 7, 2017 at 14:10
  • yes was thinking about that as well.
    – apedic
    Commented Aug 7, 2017 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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