Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112518 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 69366 invoked from network); 15 Dec 2020 20:05:58 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Dec 2020 20:05:58 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A29411804DD for ; Tue, 15 Dec 2020 11:36:58 -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.3 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 mout.gmx.net (mout.gmx.net [212.227.15.18]) (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:36:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1608061016; bh=uG8DUy72UDZM0vtT+cAT2l9lNv4LNxzQc1gtIHYufQo=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=Fze1p0vhf6RQkeDbcdAx8fDzlKGujx8RBwdrUFlUX0cOS017qK3O3m9WUPQRv1eli uiwsAze1A466966Y+KPHf8MjecrlqYcbGlnmuOJmbg4s2QyPIuJ82swbnA0960N+Ef B+umqCzhM4rgulbeJQV1U8kIfEwMKFj0pQIWsmBI= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.120] ([24.134.51.41]) by mail.gmx.com (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MfHAH-1k9rxj0Bcx-00gnIU for ; Tue, 15 Dec 2020 20:36:56 +0100 To: internals@lists.php.net References: <5f138466-1da4-0048-3cba-13c0d2da5732@gmx.net> Message-ID: <0956d65c-91ed-1d99-4b93-ce6ced83e9b7@gmx.net> Date: Tue, 15 Dec 2020 20:37:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Content-Language: en-US X-Provags-ID: V03:K1:iWF+/ssQgKkXfABolUwedbdpY9dzRaWXPVGOyFyKERWevNcX2Wb 18rMCQsosZQSEEvqanEnyRQwWfHM6M4goA3+K+GaI5Ipdo8g6nsJ0YpfJ7ev8atIhLrpFxd kqYMm1LGa29TBOMcM7hykEUMPfCln3kb3vXeLbmPhKw870mH9sny4O8gpM+FmYH1JsFcIJH cC8VztUjrhhqerZYzvlEg== X-UI-Out-Filterresults: notjunk:1;V03:K0:Kd9tvJCdcY8=:AWEfkA8N23/Evds2HUvfmn i8RGoZ8LbQ7dSOJa/P7W4uRHVhmGXkfNg/DYAvpB7+yiFR95O6iwFS6ov9pKzF5nOglQDfmoL O0pSdHuBtOSQU8lYAPRananqiy8jt7C+eGqVEV7tH3++kzIF3tOzaCFqcf/I0+QLaCUswAMLB tQ45oiFphsDoxpTzTKQKd0Re1r7Jb7itbOVS9G8Ft2QKW03A5MZZuV+NZVGOYO2MAvUBaySf+ Mr9N/J9M0GwAdWGraAccOtoL0GJKBS/VjQknpVARFuHduG38KICC85iO+xqwz4zEPc3tyHrAG NblCkrpqC4rnKFVp+TGgIK7nGzFxppriRBAXLhwn8V4Q7HWLrAtN9xmftNMa5Jf21fz+ypJtG lJWijz5WuoEu7b6y+qNjCdsi8j0fsI75Y73pXS2Xb85UGRzEw2raU+x2SleSj9Mi0eVlkafwM BqWyGQNgssf+2qfISxyFZUx5UMftdFvw+/Upuupoke66LKRV9dIIdNQIaGnkS85mG9QzAcAem qkC853URXlCHUNWu4o5wVH1rXGCaFk/U7FzPZXHygRLQNnBVMRsYXJvZD4RBpiEILHqZCLL5v KIKNnpr3YxIv7pOYvKefh4nXLOHlRthIq+n77+s32ExRvSNPfts/KWx3bEVuJO1fBVSKpFKD1 NfR0td12R9VTN4TVrvDb0Q0fYm08J9l9nnRqjDBZ5fptWAh5IlcxFK61SKhRVa9QvvGEsUbdV bjw55iVS6CeLKLDHxMYbxrzpjUAK6TC+7lvgdJnUw8De5ls1hb2EaZABHjZc+whS3oaYAynw+ 87AdDUM6QZlbhUdE7WaEb9mAdtnaNhddg9477jVnVoQtGsgdf/N+mSxRJA/ZykpgNgahvY9w+ tVopXkcW8StmyvPp/SCw== Subject: Re: [PHP-DEV] [RFC] Short-match From: a.leathley@gmx.net (Andreas Leathley) On 15.12.20 20:08, Sara Golemon wrote: > Or even better with existing syntax: > ```php > $this->handler =3D match($var) { > null, true, false =3D> json_encode($var), > default =3D> \is_string($var) ? "\"$var\"" : \rtrim(\print_r($var, tr= ue)), > }; > > I appreciate that this is a specific counter-example to your example, bu= t > you picked the bad example. :p Sure, for this specific example - there are of course longer real-life examples (sometimes even nested ones), often using instanceof, is_array, is_callable and similar constructs, but they seem a bit too much for a discussion. If you add slightly more logic then it might be better: ```php $this->handler =3D function ($var): string { =C2=A0=C2=A0=C2=A0=C2=A0 return match { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 null =3D=3D=3D $var =3D>= 'null', =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 true =3D=3D=3D $var =3D>= 'true', =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 false =3D=3D=3D $var =3D= > 'false', =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 is_string($var) =3D> '"'= .$var.'"', =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 is_callable($var) =3D> '= callable', =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 is_object($var) =3D> get= _class($var), =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 default =3D> rtrim(print= _r($var, true)), =C2=A0=C2=A0=C2=A0=C2=A0 }; }; ``` I guess that would be an advantage of these current switch(true) (and possibly future match {}) statements: it is easy to add additional matches that do not impact the others. I do like Nikitas idea to make it a TypeError for non-bool matches.