I’ve got a piece of existing code that I’m having problems understanding.
I generally don’t like shorthand because it requires config changes, and is harder for me to read. For this reason I’m not particularly familiar with it. The existing code was written by someone who loves shorthand.
When I encountered this:
if($type == 'a') $type = 'Type A'; else if($type == 'b') $type = 'Type B'; else if($type == 'c') $type = 'Type C';
I read it as a simple if, and else if string. I converted it to:
if($type == 'a') {
$type = 'Type A';
} else if($type == 'b') {
$type = 'Type B';
} else if($type == 'c') {
$type = 'Type C';
}
I thought that was pretty straightforward, however I’m getting different results in practice. What’s the difference between the two snippets above?
They’re absolutely identical, the difference must be elsewhere.
Is that a copy/paste of the before and after code?
I agree with anubhava though, I’d tend to convert that to a switch case for clarity: