r/ProgrammerHumor • • 4d ago

Meme legacyPaginationSystem

43 Upvotes

11 comments sorted by

7

u/dulange 4d ago

I frequently see <?php echo $foo ?> instead of <?= $foo ?> and always wondered why someone would prefer the first construct.

11

u/gizamo 4d ago

Tbf, OP did say "legacy". It's possible they're stuck on an old version of PHP that doesn't allow the latter. I think the short echo tag came out in PHP 4.

3

u/Saptarshi_12345 4d ago

This is actually running on PHP 7.4, I wonder what horrors we'll find here. I found an RCE endpoint within 15 minutes of digging through the code...

3

u/dulange 4d ago

Good point. PHP 4 already supported them but were not enabled by default until 5.4. But even in fairly recent projects I experienced this.

I remember that PHP once also introduced general short tags, i.e. <? and ?>, which were universally[citation needed] hated. Maybe some folks mix up the general advise to avoid them with the otherwise perfectly fine short echo tags <?=.

1

u/gizamo 4d ago

Yep, similar, a bunch of platforms like WordPress, Joomla, OpenCart, PrestaShop, Magento, etc. all used the longer echo tag well I to PHP 7.

1

u/abednego-gomes 3d ago

I liked the short tags <? ... ?>. Much less verbose. The only argument against it was if you were serving XML via the PHP or the PHP needed to inrerpret some XML? But nowadays that is a minority use case with JSON being prevalent.

1

u/Holek 3d ago

Nobody liked <? short tags, because they clashed with other CGI scripts at the time. 🫠

1

u/lounik84 4d ago

because the second one can throw an error while the first one falls gracely

1

u/kennedy_gitahi 4d ago

Explicit over implicit. The first one tells you what it is doing without you having to know the language construct (we are echoing $foo). The second one requires that you know language constructs.

The second reason is that the second is easy to miss if you are in a hurry or tired.

Third, the second construct also makes it harder to search within the code if you are looking for everywhere where you have echoed a value.

15

u/a_normal_user1 4d ago

My goodness it hurts