Yeah, I try to avoid mixing types ad hoc for this very reason. I've seen way too many bugs that result from chucking values of random types about and the resulting necessity to constantly check and recheck what types any particular variable contains ("is this an array or a string? Oh, it's FALSE. No. wait: Null").
I agree treating numeric strings as integers even in string context is a mistake on the part of the languageāI've been bitten by that before when I tried to index an array of countries by ISO3166 numeric code. But if you try submitting it as a bug I guarantee it'll be marked WONTFIX because it would break way too much existing code.
In fact, I'm not using switches that much either because they operate with only a loose idea of equality.
$return = ['ug' => 'ug', 'gd' => 'gd', 'cc' => 'cc', 'jr' => 'jr'][$val] ?? null;
if(isset($return))
echo $return;
else
throw new Exception("...");
It would be even shorter if you could have a throw
directly on the right of the ??
operator...