On 23 September 2016 23:14:37 BST, Dan Ackroyd <dan...@basereality.com> wrote:
>On 23 September 2016 at 17:40, Rowan Collins <rowan.coll...@gmail.com>
>wrote:
>>
>> I've been pondering an idea for ages of a generalised syntax for
>switch to
>> specify an operator to use, so you'd do something like this:
>
>That's technically possible already:
>
>function foobar($foo)
>{
>    switch (true) {
>        case $foo === '1':

Yeah, switch(true) has always felt like an ugly hack to me. If I ever do write 
up my idea I'll cover this in the RFC, but the main problem is that you have to 
repeat the "$foo ===" part in every case, which means a reader can't assume all 
the cases are of the same form, and in many situations you're better off just 
using elseifs.

A switch(true) makes more sense if you have a bunch of basically unrelated 
conditions with the same outcome, at which point a bunch of case labels is 
possibly easier to maintain than a big chain of boolean ors. 

Regards,

-- 
Rowan Collins
[IMSoP]

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to