![]() |
CI4 Best Practice for Echo Shortcut Tag - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: CI4 Best Practice for Echo Shortcut Tag (/showthread.php?tid=80167) |
CI4 Best Practice for Echo Shortcut Tag - objecttothis - 09-23-2021 Preface: According to PHP, as of version 5.4 `<?=` is always available regardless of the value of `short_open_tags`, so comments regarding compatibility are irrelevant. Does CodeIgniter have a best practice for the use of the Echo Shortcut Tag (e.g., `<?= $foo ?>`) vs echo notation (e.g., `<?php echo $foo; ?>`)? - PSR-1 just states that tags should be limited to `<?php` or `<?=`. - PHP states that using a semi-colon in the short echo tag is redundant. - PSR-2 and PSR-12 don't mention the tag. - Ryan Seachrest's style guide says that the echo shortcut tag should be used when possible. - Wordpress style guide says no. - CakePHP style guide says yes. - I can't find anything from CodeIgniter saying that one should be used over the other. RE: CI4 Best Practice for Echo Shortcut Tag - kenjis - 09-23-2021 Don't worry. CodeIgniter loves your choice. But the User Guide uses <?= $foo ?> style. See https://codeigniter4.github.io/CodeIgniter4/outgoing/views.html#creating-loops RE: CI4 Best Practice for Echo Shortcut Tag - paulbalandan - 09-23-2021 Our coding standard uses the short echo style whenever possible. https://github.com/CodeIgniter/coding-standard/blob/32563dfc7dfa824e489adcabc4d5b0ebf7933f50/src/CodeIgniter4.php#L114-L118 |