Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107560 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 360 invoked from network); 16 Oct 2019 18:51:45 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 16 Oct 2019 18:51:45 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 6374A2C76C0 for ; Wed, 16 Oct 2019 09:36:10 -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-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) (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:36:09 -0700 (PDT) Received: by mail-ot1-x330.google.com with SMTP id m19so20738304otp.1 for ; Wed, 16 Oct 2019 09:36:09 -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 :cc; bh=Mej4BK3hq5JevPNA4eOrvUXmlpi1ZAP0YAcjITYKeb0=; b=ASXoCZee6W098Bdf22dKoSMjA03C9hd1jifCj7MpchWBAa8Zz8tipoqK+KLm5DHt6Q 4QrVcDEjR7bOg2D3qQkesKnFKt0PIEy3+2AgeZB+e0YPFWdG+TUJzego6PuwAPWfc1BI EjfJmcvGwCGbSV3qPyM0PkwA6q4/np3pzHMwpw+5LAqMbFhloYn9hhtlygyu23QCBJc+ kzWz+obyri6Q/4ZJI4YNS4/Oiy6tgDGR5n2aa7UmdUgDsgzOSP18BwVL34iUXGIc5xMr c4jJcZrIGcvQKYNRFfjfx4/OEFeRzVnQbvDq7/4/owml1KjmcUwLCcluoUpsE6/Ds96z m7Dg== 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:cc; bh=Mej4BK3hq5JevPNA4eOrvUXmlpi1ZAP0YAcjITYKeb0=; b=auBQlWpFMh53acApdbdtBJ79urfoTL2+cvyWkkq57GXzDLZT3Ian/HrkbxUag54G/n KNgrFfCSWGYbaokqNSxpeCN/u4a/CI8pMRTEtZRFGPJdnQPYG/HwCmh3ieYAmlO/pyvb n6zOqyT6iq14FPYTikPxSn3WQQt7G94I8lmBZd94Yr/sA3lmWPGPXtbhHAEmmls4gieb iTAylCVazGGLf0IsLtDIy4GvJPydEyhygwdW8QB2BXleC9o2xaKdqn5F41XLJao8KnLt woJIfN/TSsZXfTYT6GTMsfhHgoJ7obvLPxLjON/geBaNpODIsNDAczQXw2lmecCoMfPi KNdw== X-Gm-Message-State: APjAAAX4JFdgKVaNyVExGrF7YZYNYBpqqflpwT4WC0t+IhcL2PscV77E a8ugy4qV9elGrvPMsMMopT/qQDHjp0QQHU1OzwU= X-Google-Smtp-Source: APXvYqyCXV8t6+CNNEeiC0Vey85Fy6NykO2+uioZqTqkG6vtNJbf8GOm8kxgSt2q+ljJG2Gn3mkUINL9iKqe+fBf6ZM= X-Received: by 2002:a9d:6f8a:: with SMTP id h10mr18699529otq.100.1571243769271; Wed, 16 Oct 2019 09:36:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 16 Oct 2019 23:35:56 +0700 Message-ID: To: Robert Hickman Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000b91d49059509b2e4" X-Envelope-From: Subject: Re: [PHP-DEV] Inline switch as alternative to nested inline conditional From: webdevxp.com@gmail.com (Kosit Supanyo) --000000000000b91d49059509b2e4 Content-Type: text/plain; charset="UTF-8" Hi Robert That is impossible to implement because there's no way to tell the parser that `switch` is statement or expression and it conflicts with `=>` in array key expression (that's why PHP chose to have arrow function with `fn` prefixed). And IMO your idea is harder to read than normal assignment Regards On Wed, Oct 16, 2019 at 8:58 PM 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}"; > --000000000000b91d49059509b2e4--