Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100488 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37772 invoked from network); 9 Sep 2017 12:11:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Sep 2017 12:11:11 -0000 X-Host-Fingerprint: 62.180.109.77 unknown Received: from [62.180.109.77] ([62.180.109.77:25819] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 87/77-10715-B5AD3B95 for ; Sat, 09 Sep 2017 08:11:08 -0400 Message-ID: <87.77.10715.B5AD3B95@pb1.pair.com> To: internals@lists.php.net References: Date: Sat, 9 Sep 2017 14:11:04 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Posted-By: 62.180.109.77 Subject: Re: [RFC] Match expression From: gmblar@gmail.com (Andreas Treichel) 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.