4 ms·
I prefer something a little more like: <? foreach ($users as $user): ?> <div> ID: <?=$user['id']?> <br /> Name: <?=$user['user_name']?> <br /
by DanHulton 16y ago
I prefer something a little more like:
<? foreach ($users as $user): ?>
<div>
ID: <?=$user['id']?> <br />
Name: <?=$user['user_name']?> <br />
Input: <?=htmlentities($user['userinput'])?> <br />
</div>
<? endforeach; ?>
That said, I know I'm INSTANTLY going to piss off the "NEVER USE SHORT TAGS EVER" camp, but if it's on a server I control (which is 99% of the time), or I can modify PHP init settings via .htaccess or ini_set (which is the other 1% of the time), it literally doesn't matter.
The main takeaway is the alternate control structure (foreach: endforeach; instead of foreach {}). I find that way cleaner than heredocs.
- Jach 16y agoWell, you could use USERS_FOREACH as your delimiter instead of EOD... I don't mind the short tags (and agree you should be able to enable/disable them in almost all cases) but just don't find them worth it, what I do dislike is the abundance of angle brackets and question marks and calling a function at the moment of output. (It just looks odd, and when people use their own h() function it just muddies the water. I liked Smarty for removing this.) I think PHP and Perl got it right when they allowed embedding of normal vars in strings without any special syntax thanks to the $ sigil, we should take advantage of it where possible. When you have a bunch of non-PHP I think it makes sense to drop out into normal HTML, but otherwise, PHP strings are fine and your editor should support syntaxifying them as HTML.