magento2: [2.1.0] HTML minification problem with php tag with a comment and no space at the end

Steps to reproduce

  1. Install Magento 2.1.0 using composer
  2. Create a theme and a template file which contains this:
<?php //if ($showDescription):?>
    <div class="product description product-item-description">
        <?php /* @escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
    </div>
<?php //endif; ?>
  1. Turn on html minification in the backend

Expected result

  1. Page is rendered properly without errors

Actual result

  1. Error message appears: Parse error: syntax error, unexpected '<'.

The minified php/html file was turned into:

<?php <div class="product description product-item-description"><?php /* @escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?></div><?php ?>

Temporary solution

Add a space at the end and it works again, like this:

<?php //if ($showDescription): ?>

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 4
  • Comments: 26 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Hi @hostep. Thank you for your report. The issue has been fixed in magento/magento2#16332 by @lisovyievhenii in 2.3-develop branch Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

I am working on this at #dmcdindia

@pantaoran: it’s only for php tags with php code which is commented out in phtml files. I haven’t searched the Magento core code if there are offending files like that, in our case it was a file in our custom theme. I don’t think your regex searches for commented out code?

Although I agree that all phtml files which contain {something}?> should be replaced with {something} ?> (including a space) to have everything consistent.

I’m using 2.1.6 and I’m having the same issues with html minimication