Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109594 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50563 invoked from network); 12 Apr 2020 14:18:55 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Apr 2020 14:18:55 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 532821804E2 for ; Sun, 12 Apr 2020 05:48:04 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 12 Apr 2020 05:48:03 -0700 (PDT) Received: by mail-yb1-f182.google.com with SMTP id f14so3806946ybr.13 for ; Sun, 12 Apr 2020 05:48:03 -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 :content-transfer-encoding; bh=DLEPMqX1l86In62IdkYn2c4awOm7FkLSuZah7ekDNFE=; b=HzuDbfpyZipx436UeUOaUH2GeULDNGRyL0QBzf6Hk0nZpwJzBXGxg6DrFcM9drN1sx lsJuxu1fTVl1V3b0q/tl7iKvggwXxD7XVTrUlxdUDOShEkhFe913THPkVzpYxoGtGavf kX/PzkZMWTp5Oxg6Mbt2mlnJiez6nY/H5L2lAPY9knMcH/2h6I0/c+qs8Mu+5Nor52iA MHGd78bYKn3I9brbl/L0F7cmDgfCLSob5WQArHXEUzOWIRqWPMHGhBXIpENCj+rZHnDD Kb8/T1RdyM9msWr47qwoFgkFPRkx5KWYx/9NnBYTCzFb1e5RgYDvAT5uWyuPAgW1KiE9 6GdA== 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:content-transfer-encoding; bh=DLEPMqX1l86In62IdkYn2c4awOm7FkLSuZah7ekDNFE=; b=c2sIBKBN0U97JoyjTHf3V1Zng9DuLpBe53YlQuEPA8i8D7c01eteZuYES4nv3jQ+Wz gmtPtJr0MEEPE8XP+/+egujM+YtbFTLN0bnx0my1WlNURMbkz07A+j0XuzbAxKh7yFsG xR+uSgF9VicnIjRk65Fm4YM93jcNgEOHkpftvVlg87iz0zwekJbCJiAkXOvdEjcFveje tFxN3g+cZoDCmXaLzRIAuLLpvdISke8A9bx4kK1euXzV7Obo5az9gRKN7RDs3brr1kfc ZA3MlLHATUzjViTT/K2AdrECDcIVLQZgaz5JmqpV1gU19b3KZoIhA8rqdo9aKCZfO9at vh0g== X-Gm-Message-State: AGi0PublUhMUl0wUtaR+L1kJM9lUB0/VlCe3qlTW+3AUxBpwIO0fjkQm EWlGc1u2yh31E8c8yzMxm8hMYYmkM/wxDCd8ONNN0b0g X-Google-Smtp-Source: APiQypK1M8pZBROGaMFCml+e8S3I0AONK7inuRXrPWkeXFYstwH2za7pdQ6R2pXaM7M2Vc+CiBHHPwq7Wx2tRcY5uGg= X-Received: by 2002:a25:698b:: with SMTP id e133mr19815464ybc.367.1586695679009; Sun, 12 Apr 2020 05:47:59 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 12 Apr 2020 14:47:47 +0200 Message-ID: To: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [DISCUSSION] Match expression From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Iv=C3=A1n > Would be posible for blocks to require a return statement instead of rais= ing an error? It would be possible for the blocks to return values (though not with the return keyword). I've created a small prototype a few weeks ago: ``` $result =3D match ($x) { 0 =3D> { echo 'Foo'; echo 'Bar'; 'Baz' }, ... }; ``` https://github.com/php/php-src/compare/master...iluuu1994:block-expression Heavily inspired by Rust: https://doc.rust-lang.org/reference/expressions/block-expr.html While this would perfectly solve the problem perfectly it feels a little foreign in PHP. Either way, this is something that can be discussed an implemented in a separate RFC. > Would be feasible for the fallthrought problem to use =E2=80=9Ccontinue= =E2=80=9D when you really want to chain =E2=80=9Ccases=E2=80=9D? Yes, that would be feasible. I personally just don't see a huge benefit of fallthrough. If we ever implemented pattern matching it could become unfeasible again (or at least require additional sanity checks): ``` match ($value) { Foo { foo: $foo } =3D> { fallthrough; } Bar { bar: $bar } =3D> { // $bar is unbound } } ``` Ilija