rector-downgrade-php
rector-downgrade-php copied to clipboard
match with UnhandledMatchError
Looks like code like this
try {
match ($age) {
1, 2 => foo(),
3, 4 => bar(),
};
} catch (\UnhandledMatchError $e) {
var_dump($e);
}
is currently transpiled into
try {
switch ($age) {
case 1:
case 2:
foo();
break;
case 3:
case 4:
bar();
break;
}
} catch (\UnhandledMatchError $e) {
var_dump($e);
}
which is not the same behavior, unhandled matches are just ignored.
I think an easy fix could be just to somehow add a polyfil for UnhandledMatchError and add a default in switch throwing it when there is no default in match.