Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect PHP code is generated with commented-out <?php tags #7703

Closed
DCoderLT opened this issue Jan 9, 2023 · 2 comments · Fixed by rectorphp/rector-src#3458
Closed

Incorrect PHP code is generated with commented-out <?php tags #7703

DCoderLT opened this issue Jan 9, 2023 · 2 comments · Fixed by rectorphp/rector-src#3458
Labels

Comments

@DCoderLT
Copy link

DCoderLT commented Jan 9, 2023

Bug Report

Subject Details
Rector version dev-main@71448a

Minimal PHP Code Causing Issue

See https://getrector.org/demo/06f6b4b3-883a-4f6d-9528-246001d66734

<div class="price-box">
    <?php if (($_min = $this->getMinAmount()) && ($_max = $this->getMaxAmount()) && ($_min == $_max)): ?>
        <span class="price" id="product-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
            <?php echo Mage::helper('core')->currency($_min, true, false) ?>
        </span>
    <?php elseif (($_min = $this->getMinAmount()) && $_min != 0): ?>
        <span class="label"><?php echo Mage::helper('brainvire_giftcard')->__('From') ?></span>
        <span class="price" id="min-product-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
            <?php echo Mage::helper('core')->currency($_min,true,false) ?>
        </span>
    <?php /*elseif ($_max = $this->getMaxAmount()): ?>
        <span class="label"><?php echo Mage::helper('brainvire_giftcard')->__('Up To') ?></span>
        <span class="price" id="max-product-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
            <?php echo Mage::helper('core')->currency($_max,true,false) ?>
        </span>
    <?php */endif; ?>
</div>

Expected Behaviour

When Rector reaches this endif, it duplicates the <?php tag and the block comment it saw just before, and introduces a syntax error . This should not happen.

@DCoderLT DCoderLT added the bug label Jan 9, 2023
@samsonasik
Copy link
Member

The bug seems only happen on VB-style syntax: with : and endif usage, when using curly braces {, }, it seems working ok, ref https://getrector.com/demo/5552773d-c9ac-4a0a-85a8-a877a11c8e48

@samsonasik
Copy link
Member

This issue is on php-parser itself as it duplicated comment just by printing, I created failing test case PR to nikic/PHP-Parser repository:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants