-7

Is if($var){ ... } faster than if($var): ... endif ?

Which one do you use?

user824069
  • 15
  • 4
  • 3
    Quoting myself from another one of your questions: "Forget about micro-optimizations. Focus on writing clean, easy-to-read code." –  Jul 01 '11 at 01:48
  • 6
    If you become so desperate to squeeze out performance that this becomes an issue, you shouldn't be using PHP. – Ben Voigt Jul 01 '11 at 01:49
  • 1
    Really. Who keeps upvoting these stupid questions? – mario Jul 01 '11 at 01:50
  • why is it stupid? I think it makes sense.. – user824069 Jul 01 '11 at 01:51
  • 2
    I recommend `if () { }` inside large blocks of PHP and ` ` inside HTML blocks, for **readability**. I *do not* differentiate them on speed, because there's probably no difference. – deceze Jul 01 '11 at 01:51
  • 1
    I wouldn't exactly call it a "stupid question". If he doesn't know, he needs to. That isn't to say that there aren't plenty of stupid questions out there ;) – Jonah Jul 01 '11 at 01:52
  • 4
    Obviously, because you didn't spend much thought on this or read the replies on your last questions. To answer it: same bytecode. Negligible difference for the tokenizer and parser. – mario Jul 01 '11 at 01:54

2 Answers2

4

I'm sure the difference is negligible, if there is any. If the difference is important to you, you should probably use a faster (likely compiled) language.

You would do better optimizing more intensive things, like databases first (and writing clean code, as @Tim stated).

Jonah
  • 9,991
  • 5
  • 45
  • 79
0

I think both are the same. Personally I prefer if($var: ... endif;. php is a template language and that syntax leads to extremely well toward it. I actually put all variables in <? ... ?> tags to keep it all clean and concise.

locrizak
  • 12,192
  • 12
  • 60
  • 80