Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112517 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 66470 invoked from network); 15 Dec 2020 19:38:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Dec 2020 19:38:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5C75B1804C6 for ; Tue, 15 Dec 2020 11:09:04 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 ; Tue, 15 Dec 2020 11:09:03 -0800 (PST) Received: by mail-lf1-f45.google.com with SMTP id s26so7546237lfc.8 for ; Tue, 15 Dec 2020 11:09:03 -0800 (PST) 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=axMzkegJIyC0ZhOlBrtlO50/chdB5O9f6D3HLO8VR70=; b=YI7eEZ+cwObW/Br1Y4CvUo83VaIjk9rE+g/R2GdcD0UM129t7PUPTLtTeD2HvjPa4J 0fhqe8RNvS9hMGE3AqweFw7MzNSanZK81uvYypxU35VCaxGFeFtXrEVFlTQrmu6K1Uq+ GDgLnaGibUGs54GVk/xqWtgwW9ggTBYkPsnDUuqBRd8frlnTVdROxrSnmCMEKfZaB2j5 poXvXERdEBB4RrZf0vY3sFmgGNpoOex9PdL5zbtISrqv4G4oDbg81SC5QQOLPhJ9mM5x ZEoPThr0tMBTWIROa7QLrgBcv6WR+uDqqGp9oSyz3J93Y+HCPpDQola0Nt2BtRD2Quqx wLGw== X-Gm-Message-State: AOAM531s2TQnZyu2deOM4LrLSGb0hrAmh4GA45UAbdGNwPV48Pan9V3S bDVa3AgtUMgS7kBWiUsPlyw5xCU+n7cDgrV/8PJMKQ== X-Google-Smtp-Source: ABdhPJyZxKUTdBXlvWrv481JAfjNQXgtlrk+CvqpLyHWg9AAe2tt99xDii7AdYU6HqaZnYScgeZmDDYVCYfYSP1zUOk= X-Received: by 2002:a2e:8118:: with SMTP id d24mr12845585ljg.105.1608059340746; Tue, 15 Dec 2020 11:09:00 -0800 (PST) MIME-Version: 1.0 References: <5f138466-1da4-0048-3cba-13c0d2da5732@gmx.net> In-Reply-To: <5f138466-1da4-0048-3cba-13c0d2da5732@gmx.net> Date: Tue, 15 Dec 2020 13:08:49 -0600 Message-ID: To: Andreas Leathley Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000c88f8d05b6857d48" Subject: Re: [PHP-DEV] [RFC] Short-match From: pollita@php.net (Sara Golemon) --000000000000c88f8d05b6857d48 Content-Type: text/plain; charset="UTF-8" On Mon, Dec 14, 2020 at 5:30 PM Andreas Leathley wrote: > With match this becomes much more concise: > > ```php > $this->handler = function ($var): string { > return match { > null === $var => 'null', > true === $var => 'true', > false === $var => 'false', > \is_string($var) => '"'.$var.'"', > default => rtrim(print_r($var, true)), > }; > }; > ``` > Or even better with existing syntax: ```php $this->handler = match($var) { null, true, false => json_encode($var), default => \is_string($var) ? "\"$var\"" : \rtrim(\print_r($var, true)), }; I appreciate that this is a specific counter-example to your example, but you picked the bad example. :p -Sara --000000000000c88f8d05b6857d48--