Forum Moderators: coopster
If the statements aren't necessary than there is no need to include them. But i guess its a matter of preference and performance.
Apparently just like you can have variable variables, you can have variable functions as well... [us2.php.net...]
Something new learned every day :)
eelix
if (condition)
statement;
statement; // then you add this and the code breaks
else
So, if you never make a mistake, you're fine; otherwise you mind want to go with the blocks, no matter what, just to be safe.
Chances are pretty good that in any script that I write, I'll use the block form. If I switch to the unblocked form just because I can then I may end up with both types in the script. Someday I may have to troubleshoot that script.
In my opinion writing consistent code today will make any future work all that much easier. I use the block form in nearly every case, simply as a matter of consistency. In my shop thats a standard of good programming.
I only omit statement blocks rarely, usually to make the PHP shorter when it's a tiny bit inside an HTML tag. To me, it makes it more HTML-like; I hate it when there's a huge tangle of HTML and PHP, with snippets of HTML surrounding long bits of PHP, and then loads of echo statements scattered in the PHP -- makes it harder to write nice HTML. I guess I just plain don't like mixing the two unless I have to :D
<h1><?php if ($h1) echo $h1; else echo $title;?></h1>
This makes more sense to me.
As for the variable functions, well I'm glad they're there, and I discovered them completely by accident! (Which is why I was unsure about them.)