performance - PHP: are switch-case statements with strings inefficient? -
in php layer i'm receiving error codes strings ("not_found", "expired", etc). it's small list of possible strings, perhaps dozen.
what's efficient way of dealing these? using switch-case against string constants stored in class, or should parse them numbers (or something) first? or php smart enough doesn't matter?
you might want consider using constants? let's have class error , define error codes there this:
class error { const not_found = 0; const expired = 1; // , forth } and can use them in code accessing them error::not_found , switch statement wouldn't need compare strings has plain ints without downgrading readability.
Comments
Post a Comment