Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107559 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93632 invoked from network); 16 Oct 2019 18:16:49 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 16 Oct 2019 18:16:49 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id B95F52C43CF for ; Wed, 16 Oct 2019 09:01:15 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Wed, 16 Oct 2019 09:01:15 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id t5so3153104ilh.10 for ; Wed, 16 Oct 2019 09:01:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=tzt2qC6hXRoJdw6UmLyv31PYYISNwDKqZGpwmZoJSh4=; b=GdPvlh8+PNVbSV1AvunovjhVjvmXdHS3VH04etJ53s/+CjxBq1IzB/cZ0BCReWswrO ZGppq4LKeHnm9rTqsxVOtiVuQOR1lYvoYtZm6yzJsg5qVVAlvzvQA7FocwLA/dv7Yuao 2UXTro6iO+poCZJcybtM94T50cfsRX64W2eujTUj+pqtUUtNowh/TeUCelx+jZO3HQV5 sBCKrghUE7Eo2gXg1uZmPqLzL9DQz9Xxs6+OASBGLNjjnoXDtm9g5/6nh9K6cPKd65SW lBA8XwFurbp6HAbiB+l55mEwA7vf8yu6+bHwmoigGMPTItWZ2nQU1dfka3UifuQ1YDA8 fOgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=tzt2qC6hXRoJdw6UmLyv31PYYISNwDKqZGpwmZoJSh4=; b=TQfowhiYJgv7/ZajRbzc/YyQX4a3T+wKQ+joWqRI+XruW+U4wyqL4pDW4bmAaWbh3N DlwpLKu6ie5+04jhoGqaxyaY7ho/uGBGOPQJxMJkOedk00W4T1PapU81MtwLtfljFNjg 44VBSyAkiEGLFfY+G3LHDkUoLtR5+h4AtEAdXvdLrWzMEu8jonvJtVXOHuB1qnFf6I6k jFEMwd2lpUG9juehNTs4bSR8fD0B8fwzZiiKTse4zuZFH/V8uVGpB9qO++0SauwB9tww ceWtsOW08tKieThO/msCCLZ0SkJjtts+3c+gzu03DKZTjTwEsuIXVPzN9mzK8z+jjSHH dHpQ== X-Gm-Message-State: APjAAAUjBbQJXndxZxlxH1jeoT5WZqk9QGQuG/POfymfhPDDqNg7uYtH zp/VA/QxT3F0hdkJntQZjzbgCOYf+n/0jLOzbnDS52bK X-Google-Smtp-Source: APXvYqwscurcMsqkYqU1oFcfj9zWzitQVoi+F5/hrx+EO3yggGEqg1r06OYsF8qzFubShfME9Es8XrB2alNk6iL+rM8= X-Received: by 2002:a92:4144:: with SMTP id o65mr13239793ila.206.1571241673884; Wed, 16 Oct 2019 09:01:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 16 Oct 2019 17:01:02 +0100 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000d408f70595093515" X-Envelope-From: Subject: Re: [PHP-DEV] Inline switch as alternative to nested inline conditional From: rowan.collins@gmail.com (Rowan Tommins) --000000000000d408f70595093515 Content-Type: text/plain; charset="UTF-8" On Wed, 16 Oct 2019 at 14:58, Robert Hickman wrote: > > > > > $say = switch (date("w")) { > > > case 0 => "weekend!"; > > > case 1, 2, 3, 4, 5 => "weekday :("; > > > case 6 => "weekend!"; > > > }; > > > echo "Today is {$say}"; > > If you had a really long expression, it may be easier to read if the > assignment was moved to the end, perhaps like this: > > switch (date("w")) { > case 0 => "weekend!"; > case 1, 2, 3, 4, 5 => "weekday :("; > case 6 => "weekend!"; > // lots more cases ... > } => $say; > > echo "Today is {$say}"; > The assignment is not part of the switch syntax, the proposal is for a switch expression which evaluates to a value, and can be used anywhere a value is wanted. Your example is no different from a complex function call: $say = doSomething( $foo, 'weekend', [ 'blah => 42, 'bob' => 'smith' ], moreStuff() ); It might be nice if there was a left-to-right assignment operator (there are some languages which write it that way around), but that should be a separate feature, where you could also write this: doSomething( $foo, 'weekend', [ 'blah => 42, 'bob' => 'smith' ], moreStuff() ) => $say; Regards, -- Rowan Tommins [IMSoP] --000000000000d408f70595093515--