I am going through an older module created in PHP 5.x.x and we have just moved the website to the php 7.2.x so we suddenly got the error in a helper class

Uncaught Error: Using $this when not in object context in

There is a dispatch event in helper that is using the following code there:

Mage::dispatchEvent('magento_string_filter_before', array('content' => $contentObj, 'object' => $params['object'], 'params' => $params, 'helper' => $this));

and i believe that is not compatible with the PHP 7 so how i can convert this and what replacement we have?


  • Are you trying to pass the object of current helper, right? Aug 7, 2020 at 6:19
  • Yes you are right! Aug 7, 2020 at 12:59
  • You need to replace $this with your helper class. Aug 8, 2020 at 9:30

1 Answer 1


I have pass the object of the helper as like

replacing $this with following:


and code looks like this now and working fine for.

Mage::dispatchEvent('magento_string_filter_after', array('content' => $contentObj, 'object' => $params['object'], 'params' => $params, 'helper' => Mage::getSingleton('my_helper_here')));

Your Answer

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

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