Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113811 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 35789 invoked from network); 27 Mar 2021 15:18:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Mar 2021 15:18:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E47A71804D8 for ; Sat, 27 Mar 2021 08:14:49 -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,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 ; Sat, 27 Mar 2021 08:14:49 -0700 (PDT) Received: by mail-lf1-f44.google.com with SMTP id m12so12054936lfq.10 for ; Sat, 27 Mar 2021 08:14:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=dQFe8n3wzvQrqaBNAQWIxIW2b2tOtpQRti4D8eQt5bY=; b=uX6b8jc9AB+z+jgaVPPfC4KrXgczHW8Vx1qEoPVZJIFUxv5OrjILunlT7dtYvSDekG CRfYnFfyh4Anal+8WB/CRKe3hLIEbAJTl0AzQKZR+FU4eFKnDP+j2rW99PDCTkJ2Fl2j CIIjv9V3HjbiC+y5DkN5RrcpwaI59cbGzAe3cZ268KRSxFJoT9AaNx5AxA78x1RSdhNn NaXc6uiB6uMJuQm9T2h8TUQI6MKLbdKQBuROQG7VSzVVrn1Xz3wLxp1nOhR3iL7C5xwY CmtPlPr7t9zFZ3hPunSkAUMlhHSF99MGBqurosRsRd/MApoDhU8+eF0Zc6p0e1zjyxBR GPWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=dQFe8n3wzvQrqaBNAQWIxIW2b2tOtpQRti4D8eQt5bY=; b=nGVPIalf0L1v/M9I09SjCCSLELc7ueZsC0omD7Vshn1iYtzBl9bkpaLTB+tACMgXYQ fCYbLE7YfF1Gy1ab6o7byU/QIqYUmfViAnzgUlqlTN7TSmH1Ks/lKfWgqaMiZ64VEiLL r/2P04dmGp7l005B/DUHJzsOQvc+L0HOo4IoQBTA8qxi0J9ydsyg+cnt92cDXBJDww+N Qkl7sDtiPo2NSm4S3vVtZDSFuuY9LcUbnyGYr7kdxD5nscf7wK0xQIqfeIVssCJcks9N +2tr+spPcm9qW8iLaMYJyiz7u0CNPkaatOPp8TlY0Q9/T7R/ueJUz/Mg5mebJv1TO1Su 6u/g== X-Gm-Message-State: AOAM531H08Dq4d+ptD8bv1gDcROZxztZJQF/6Q3c4Qh7VaQQOTctEye5 HDQE5xE4fiTypwUMqrQasQ1cBaSepDLm08YQsfk= X-Google-Smtp-Source: ABdhPJyWjdvbwfdy+KJsMK45GgEBMmoPCivHHOJtQ76KPBoxzSTkX6sPmOYYufclS/vQbdEzEuwBt96aaKBFwKPKpb4= X-Received: by 2002:a05:6512:3ba9:: with SMTP id g41mr11085047lfv.421.1616858087154; Sat, 27 Mar 2021 08:14:47 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ab3:5f8f:0:0:0:0:0 with HTTP; Sat, 27 Mar 2021 08:14:45 -0700 (PDT) In-Reply-To: References: <6cfa387a-9f7b-0cb8-2bf0-3856e2f251fb@gmail.com> Date: Sat, 27 Mar 2021 16:14:45 +0100 Message-ID: To: Rowan Tommins Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Making "match" catch exceptions From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) 2021-03-27 15:30 GMT+01:00, Rowan Tommins : > On 26/03/2021 22:58, Olle H=C3=A4rstedt wrote: >> You can't catch the value of $temp in the match-case? >> >> $foo =3D $bar + match (doSomething()) { >> $temp =3D> $temp, >> exception SomeException =3D> 0 >> }; > > > $temp doesn't have an outside value, it was an inline assignment to > capture the value of doSomething(); essentially, I wanted this, but > without executing doSomething() twice: > > $foo =3D $bar + match (doSomething()) { > default =3D> doSomething(), > exception SomeException =3D> 0 > }; Yeah, I got it. Maybe I didn't read enough about the match-expression implementation in PHP, but in OCaml it's possible to capture whatever value the match evaluated to, like: let number_as_string =3D match number with | 1 -> "one" | v -> "number is " ^ string_of_int v ("^" is string concatenation.) The point of using a variable name like "v" (could be anything) instead of "default" is that like in your example, you don't have to execute the method twice. You can also add guard clauses, like "v when v > 10 -> ...". If you don't plan to use the value, you can use underscore, "_", which I guess would be the corresponding functionality to "default" in the PHP implementation. Olle