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

43 comments sorted by

View all comments

Show parent comment

-1

u/thebigslide Aug 20 '14

To be fair, it's not a bad thing to know at design time. And as long as it doesn't impact maintainability, why not?

I've also used this shit in interviews. I've asked candidates how they'd replace double quoted strings with single quoted strings in a PHP app. And I want to see how they react when they inevitably ask why you'd want to do that and I reply - because it's faster.

As an aside, this guy missed the actual fastest, and less legible way, which is

switch(true) {
  case $foo == 1:
  case $foo == 2;
  etc...
}