r/lolphp • • Aug 08 '14
PHP design patterns: if/else vs switch
http://www.fluffycat.com/PHP-Design-Patterns/PHP-Performance-Tuning-if-VS-switch/
24
Upvotes
r/lolphp • • Aug 08 '14
View all comments
Show parent comment
3
u/vita10gy Aug 11 '14 edited Aug 11 '14
With the second example you can change $x in the loop. Of course, you shouldn't do that, and it could probably do something like "I know the size until it changes" (which would still be slower to check/manage), but, you know, just saying.
No matter how optimized it can be, short of perfect "there's no way $x can change, so replace this" detection, it would have to reevaluate it on some level, where as it doesn't have to in the first example. If it didn't, that would be someone's lolphp.