Skip to content

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

Closed
@brendanfalkowski

Description

@brendanfalkowski

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.
*/ ?>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions