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

PHP short echo is an anti-pattern and should be removed #14111

Closed
brendanfalkowski opened this issue Mar 15, 2018 · 5 comments
Closed

PHP short echo is an anti-pattern and should be removed #14111

brendanfalkowski opened this issue Mar 15, 2018 · 5 comments
Labels
Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed non-issue

Comments

@brendanfalkowski
Copy link
Contributor

The PHP short echo used widely in PHTML templates cannot be commented out easily:

<?= //$block->getChildHtml('will_not_work') ?>

<?= /*$block->getChildHtml('will_not_work')*/ ?>

You must star comment the entire declaration, which is tedious:

<?php /*
<?= $block->getChildHtml('will_work') ?>
*/ ?>

And also breaks another necessary commenting use case:

<?php /*
I should be commented out, and I am.

<?php /*
<?= $block->getChildHtml('will_work') ?>
*/ ?>

I should be commented out, but I won't be.
*/ ?>

The PHP short echo should have been considered an anti-pattern because it restricts commenting, which is a hallmark of good code.

The standard echo is far more flexible and barely more verbose:

<?php //echo $block->getChildHtml('will_work') ?>

<?php /*echo $block->getChildHtml('will_work')*/ ?>

<?php /*
I should be commented out, and I am.

<?php //echo $block->getChildHtml('will_work') ?>

I should be commented out, and I am.
*/ ?>
@magento-engcom-team magento-engcom-team added the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label Mar 15, 2018
@brendanfalkowski
Copy link
Contributor Author

Found a workaround. Closing.

Reference: https://twitter.com/mostlymagic/status/974154073736753152

<?//= $block->getChildHtml('will_work') ?>

@brendanfalkowski
Copy link
Contributor Author

Actually that's not a viable workaround because most servers disable short tags (but apparently not short echo.

@Igloczek
Copy link
Contributor

It's part of PSR-1 and shouldn't be considered as a anti-pattern.
https://www.php-fig.org/psr/psr-1/

@ishakhsuvarov
Copy link
Contributor

@brendanfalkowski Thank you for reporting.
This is intentionally implemented this way. You may use #1563 for reference and more information.

Closing as non-issue

@brendanfalkowski
Copy link
Contributor Author

I guess the PSR people never comment out code.

Seems like a valid need but ¯_(ツ)_/¯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed non-issue
Projects
None yet
Development

No branches or pull requests

4 participants