Skip to content

Use short echo tags in phtml templates #107

Closed
@colinmollenhour

Description

@colinmollenhour

PHP 5.4 has made the short echo tag <?= always available regardless of the short_open_tag setting so this feature is now 100% future proof and using it in templates reduces quite a bit of unnecessary typing/characters. The feature has been in PHP forever, only before 5.4 it could be disabled in php.ini.

Proposal example before:

<dt><?php echo $this->getFoo() ?></dt><dd><?php echo $this->getBar() ?></dd>

Proposed change to:

<dt><?= $this->getFoo() ?></dt><dd><?= $this->getBar() ?></dd>

I'd be happy to tackle this by writing a script which can do the replacement with a regex. I think it won't be hard using a lookahead to make sure the replacement is only done when there is one statement between the open and close tags (detected by semicolons).

Note, I am not proposing changing all tags to short tags, just the ones that contain a single echo statement on one line.

If you approve I will start on the script. Actually I would probably use DAMit which would make it easy for everyone to convert their code if they so desired:
http://code.google.com/p/dam-tools/source/browse/trunk/DAMit.pl

EDIT:
For users of PHP versions prior to 5.4 it should be possible to force short_open_tag to "on" via .htaccess.

php_value short_open_tag 1

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions