I have submitted one module in Magento Marketplace. They gave me 2 errors in my code.

Use of echo language construct is discouraged.

Use of exit language construct is discouraged.

For echo, I have added /* @noEscape */ before echo.

But for exit, I don't know, how to solve error.

Code piece from Observer.php

           if ($maintenancePageBody != '') {
                if ($redirectPage == 0) {
                    /* @noEscape */ echo $blankpageMsg;
                } else if ($redirectPage == 1) {
                    /* @noEscape */ echo $maintenancePage;
                } else if ($redirectPage == 2 && $customUrl != '') {
                    header('Location:' . $customUrl);
                } else {
                    /* @noEscape */ echo $maintenancePage;
           // exit; /* my code */
           $this->getResponse()->setBody(); // I used this line instead of `exit`

Magento Marketplace error is,

Use of exit language construct is discouraged.

File: Model/Observer.php Line: 717 Column: 17 Source: MEQP1.Security.LanguageConstruct.ExitUsage


I submitted extension again. echo error still occurs. $maintenancePage variable has HTML content.

Would anyone please help me, what should I do for echo and exit ?

  • Is there any need of exit? You can remove it and use return instead. Commented Mar 2, 2017 at 5:48
  • Thanks Jaimin for reply. I have tried return, but my code stop to work.
    – Prince
    Commented Mar 2, 2017 at 6:04

5 Answers 5


if in controller's execute method , echo $a;

then please replace

echo $a 


return $this->getResponse()->setBody($a);

Here is official set of rules and sniffs for PHP CodeSniffer tool - https://github.com/magento/marketplace-eqp

Run it and fix all highlighted issues!

More details - http://docs.magento.com/marketplace/user_guide/extensions/review-code-validation.html

  • Simple, yet very effective advice here. This is definitely the correct answer.
    – df2k2
    Commented Sep 11, 2019 at 7:01
Use of die language construct is discouraged.

Use of exit language construct is discouraged.

Recommendation: setBody() response object method should be used.

Use of echo language construct is discouraged.

Use of print language construct is discouraged.

Recommendation: Architecture of the extension should be changed in order to avoid usage of echo, header etc. in classes, consider using setBody() method of the response object.

For more see here.

  • Thanks Arunendra. I have read that but I don't know how to use setBody(). I am new bee in Magento. Would you please help me by my code or any other example ?
    – Prince
    Commented Mar 2, 2017 at 6:05
  • @Prince this might help you on setBody() : stackoverflow.com/questions/4441526/…
    – Arunendra
    Commented Mar 2, 2017 at 6:09
  • I have tried that example but I got Fatal error: Uncaught Error: Call to undefined method Vendor\Module\Model\Observer::getResponse()
    – Prince
    Commented Mar 3, 2017 at 6:28
  • use this code Mage::app()->getResponse()->setBody('Some Response');
    – Arunendra
    Commented Mar 3, 2017 at 7:16
  • Module is in Magento 2. And your comment example is in Magento.
    – Prince
    Commented Mar 3, 2017 at 7:28

If you are getting download content from inside loop, then use like this

while ($buffer = strip_tags($ioAdapter->streamRead()))
   $myContent .= $buffer;

//Set content to CSV

And replace exit; with return;

This resolved my problem. Hope this helps.


Follow FireBear advice regarding the codesniffing.

I can tell you, though, that you aren't really on the correct track. What you are trying to do doesn't make much sense to Magento2.

First, it seems you are using an Observer by this:

Code piece from Observer.php

If you are not using an Observer to intercept an event, then you should probably change the name of your file from Observer.php. Very misleading.

For the most part, you cannot echo any output except in template files, those are the .phtml files.

Next, if you are truly observing an event, you'll definitely NOT want to cause any interruption of the code execution with header(), nor will you want to echo any output since Observers are not meant for that.

Events and Observers: https://devdocs.magento.com/guides/v2.2/extension-dev-guide/events-and-observers.html

Observer Best practices: https://devdocs.magento.com/guides/v2.2/ext-best-practices/extension-coding/observers-bp.html

If you do want to run some code and return output for a template or frontend rendering, then you'll likely implement the Magento\Framework\App\ActionInterface

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.