Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112519 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74877 invoked from network); 15 Dec 2020 21:12:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Dec 2020 21:12:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3419B1804E4 for ; Tue, 15 Dec 2020 12:43:28 -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-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 12:43:27 -0800 (PST) Received: by mail-lf1-f52.google.com with SMTP id l11so42919869lfg.0 for ; Tue, 15 Dec 2020 12:43:26 -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=LXxSZlQaGzS1O66VXPBPlABta/VCk7oI+JNv/moJxB8=; b=pyHQtS/CEj7u1GRvvsgHK5Y85UggZTb190+he/YEU5myYXGzEQ38VMeXFHmtvw9out TXbXhMBaVNrMTURxkHE2k3oEeGqFNXj1C9pWL95aVOc6ttRLlBPoUBavwdK8cOhTWckw gt3W87SOqpYVoEmrBUxiyH+h1mUVfQ45+Xk4zSddUEOKdmz6vMKbSRtPD4ey3/vraK1n GAE0ROQoTcQqIn6iCudnGdr5moxm+SdiePYu9QHBvRxvvVUgAfnedtQGvoRCd4Op76kH i7C6b71GosXTHbpFhotBYmE7m5r/DU5/xP7ZX+Oe6JSySSm3DaeeYMcakhCyY6RJySPR +EoA== X-Gm-Message-State: AOAM531VTDl1tl91AZ94/gnSF26DS9n4pbKjBI4PIcHqTJnzEJU4ZtZg HtDO5J0FpkNCHkg3l7bFrD48FBJXgX/EGahBOFmwqA== X-Google-Smtp-Source: ABdhPJzkpAUHV4iWs8u0dOjmAPg53xG8vRif1F/MBa/85eq8WiGo1CDg5OavXe5XBgr3564LsvXLenqUedcW52ygABM= X-Received: by 2002:a19:c001:: with SMTP id q1mr10941126lff.55.1608065002493; Tue, 15 Dec 2020 12:43:22 -0800 (PST) MIME-Version: 1.0 References: <5f138466-1da4-0048-3cba-13c0d2da5732@gmx.net> <0956d65c-91ed-1d99-4b93-ce6ced83e9b7@gmx.net> In-Reply-To: <0956d65c-91ed-1d99-4b93-ce6ced83e9b7@gmx.net> Date: Tue, 15 Dec 2020 14:43:11 -0600 Message-ID: To: Andreas Leathley Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000003ff10b05b686cf46" Subject: Re: [PHP-DEV] [RFC] Short-match From: pollita@php.net (Sara Golemon) --0000000000003ff10b05b686cf46 Content-Type: text/plain; charset="UTF-8" On Tue, Dec 15, 2020 at 1:37 PM Andreas Leathley wrote: > ```php > $this->handler = match { > null === $var => 'null', > true === $var => 'true', > false === $var => 'false', > is_string($var) => '"'.$var.'"', > is_callable($var) => 'callable', > is_object($var) => get_class($var), > default => rtrim(print_r($var, true)), > }; > ``` > > I saw a proposal connected to match about a year ago that included type based matching, something like: match ($var) { true => 'true', false => 'false', instanceof int => "int($var)", instanceof string => "\"$var\"", instanceof object => get_class($var), instanceof DateTimeInterface => $var->getTimestamp(), default => rtrim(print_r($var, true)), }; That might satisfy at least one of the use cases in a general way. > I do like Nikitas idea to make it a TypeError for non-bool matches. > > Yeah. Within the context of this featurette, that's something we should include in the proposal. If you're doing a match(true/false/other-literal) (explicitly or implicitly) then your cases should be commensurately more well constrainted. -Sara --0000000000003ff10b05b686cf46--