Re: [RFC] Match expression
| From: | Andreas Treichel | Date: | Sat, 09 Sep 2017 12:11:04 +0000 |
| Subject: | Re: [RFC] Match expression | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-100488@lists.php.net to get a copy of this message | ||
Hi,
Something like:
function match($x) {
switch(true) {
case $x === 1:
return 'Tiny';
case is_numeric($x) && $x <= 10:
return 'Small';
case is_numeric($x) && $x <= 20:
return 'Medium';
case is_numeric($x) && $x <= 30:
return 'Large';
case is_numeric($x) && ($x >= 31 || $x <= 100):
return 'Enormous';
case $x instanceof Foo:
case $x instanceof Bar:
return 'What?';
default:
return 'Unknown';
}
}
the problem is you need is_numeric because no type safe version of <= and >= exists.