Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112514 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 13504 invoked from network); 15 Dec 2020 09:40:19 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Dec 2020 09:40:19 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2DB951804F3 for ; Tue, 15 Dec 2020 01:11:13 -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=-0.2 required=5.0 tests=BAYES_40,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-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) (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 01:11:09 -0800 (PST) Received: by mail-yb1-f170.google.com with SMTP id w135so18230598ybg.13 for ; Tue, 15 Dec 2020 01:11:09 -0800 (PST) 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=qt17ZY+Ze1nmlk1XNxTuxqZi3iuAMSmOmtaCvqZFlpM=; b=XOcAWgMBkTQ3m2gJy3asDgSL4yElU96lS5Q22Gy+M2ntmhWTJ8XFJYGVZXVxeCLnQN ZXB3Z2udkzpv89iAUh4foTT/eqHf2vXEXlkcxyeRQdCK1+tOHy04MZTnKCaGrzKHM3JQ OWaF4I6kVVsZ1HaG4cs7AXVobNWJLGwgiXSg5xcO2oOY/qEX2KhRtwkOzk5+WzrnFonF hyuH13F98B6ru7kVuyGPS96s9DSwjfhdc+B9EXHmrjDESxuLqtlAWfNqMJZ5SHxaqmz5 m/PmSas1yuLP+Qk+rpPDSnQqvPqW5o+kr0vc/hytwKbi14R3sLEv5tsrPo5qkEfcBARL biwQ== 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=qt17ZY+Ze1nmlk1XNxTuxqZi3iuAMSmOmtaCvqZFlpM=; b=qXGuy22SGI7k3/WevI9n70GFOE9ja1o5OQdTCYWfSfjy5KokwLgYNCTmGlWxl+u+fV 5bvA4k+PacSu20/AKYeQInFElE63bvEOGNzKaTIPTN2VvANlBLpkFCYhc6nmESofjP6J skLjhBbq4I4c3mmM4DSl09xSK25BjbdOhCryPDWcU16d5B1mpKJVv3v27VKezIJ55DgS LLAv2rH+SiEFbdrl1ZKslJZF4pHy4555DPjVvomATaGc14eVrIJTZk1BS6+2aBTzdXz0 Kxb3ZMwilqs2uJJ0BHbUI3BULaEVCQr/Gbw/dzjLkPMiUvGV7OAU59gEljk1EQoX88SM XLDg== X-Gm-Message-State: AOAM533h5DPNF1JANB8Zed3ZiHD6YK76dITyj1m8FuQ8XEQEh76hTt3E 7uCfek0ozb8/I01rNtbm37JH0FrHOegJwXoE0/1wKa2nWDzX5A== X-Google-Smtp-Source: ABdhPJw1aa3FfXT/c6n5UGYddGRXqJDIULgcG2GZTVyLg+UNXA//lxkqKgWSx1KdfeZUP16FzleYUXAYh3eF0u042SA= X-Received: by 2002:a25:4446:: with SMTP id r67mr18189910yba.297.1608023466542; Tue, 15 Dec 2020 01:11:06 -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 10:10:54 +0100 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Short-match From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi internals > 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)), > }; > }; > ``` I suspect most use cases of `match (true)` are exactly for things like this where you're always comparing the same value but not against fixed values but "shapes". I think some simple and limited pattern matching would be useful here. ```php $this->handler = function ($var): string { return match ($var) { null => 'null', true => 'true', false => 'false', is string => '"'.$var.'"', default => rtrim(print_r($var, true)), }; }; ``` This would have some significant overlap with the short match proposed here. Combined with the unclear semantics (strict comparison? loose comparison? type error on non-bool values?) makes me unsure if we really need the short match. Ilija