Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123718 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 69D221A009C for ; Fri, 21 Jun 2024 01:36:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718933846; bh=sXFWx3O62BBd8RHDBHFUgnEQZRt6YLRYYrHLcDp94Vw=; h=References:In-Reply-To:From:Date:Subject:To:From; b=NAb8l15TSg3o6uZqNyKls0OLnJ6QzirH/h3AQ958ShyiKzIvv4O/CxrMRZ0DDDayi bUR2jTWt8vNowbnPdBnCIWZY6vaiA2SB3wT88ltgvlBmt0PZVIq2B/kwLI/+uVxEzj Uw37ViK+vCJ5Jc6ov1OPi6lZoyeBeUupS8+nLeX6SgXGiq0IlRTjs/y2bQKx80qxcY nTl4lTh19dqndJZTkQAWOM/WMkFVRQFiXehsvB0sYsD78wYsCJ5MYeYWm9c7mqVmzY vXnEMoX+5pfv1Jo2hD8XGJhmmvRhRf9HmK83EH2oxnz19dMBDob1qZuie/aYD2QP3X q86wBbymNO5/g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 12D05180069 for ; Fri, 21 Jun 2024 01:37:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 21 Jun 2024 01:37:21 +0000 (UTC) Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-dff26b612a9so1391819276.1 for ; Thu, 20 Jun 2024 18:36:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech.net; s=google; t=1718933767; x=1719538567; darn=lists.php.net; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=sXFWx3O62BBd8RHDBHFUgnEQZRt6YLRYYrHLcDp94Vw=; b=Hkp+xGPfTlOgAXmD0dYvsplOvZSPwBNKQ7Yra2hqm57zflsqSjboJ0KrKYkgmQsX0j LeNAUWd00Kcam5xIe7w2+OoywUBzuk5YMiEkjtQ9h85yjJ4b3RGg2DqMkYsaMHeBehEZ pIl9m1nLnl+PyfeI/6/gD9FAfs4Ede+2/8atQN9lXALOYPIWMNgK2C6bS29Ka2CCRriS iqke4RB4aXPpcEuFVY/pAzGSUtiMmjiCVGEEAYCKMem5IsPPYc1hN6ev8ihagg8VGxQQ kK+/f6nDy8zNlN66zZpa7wSOSOc+Ysnysqwtzw0PsNgFIaPjQnBLpTBZ0w5svhUxkHJK uEkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718933767; x=1719538567; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sXFWx3O62BBd8RHDBHFUgnEQZRt6YLRYYrHLcDp94Vw=; b=T1IMvOp+Epw20G9aFddlYwW55ZuDkG6Tc70Cvo0QXv6R451twUFMuOm5XwmYb0AbYc QwQ6ieguPug0/XpzmR8DHGNC4HMMmvGNBPgrSqP+icCT6Ona0hrRmIpgrCJBIF8m+gIF Bl0RbZ58S+Kh0BzgI9Ls+sokjEl7bYjQfMumpaHY607cz86X7cuenLl3+SUYLfDxjSX+ PFTIVTYtqHW78oR9WcR82bR3oj8OA2owFyYCQCXV4PVWa3J3PsKhL56Uj9s+bgHO9D9g QgeTmC/BH2CV5+kq3zTfmaGiBhsU+pjI/L62KjssnO/G7WGKun10WqR5SNob7ZaDrgau rQFQ== X-Gm-Message-State: AOJu0YyzWnHQYZ1FDmhFcK0Vs19zCtHXHx4MLElJ5+J94IzHWT+hDrpe iokVP7d0kn00mIA1iWBURGq49poacgqa4V9T9KSdiGIrhMxYJdPrkY3RzhCmfjelVLVfM5fllpR YWMln0AZr3wxjgvIZqjob2BdXrvZ54SNViMvv6jYnsoyeOjBiwPoFIA== X-Google-Smtp-Source: AGHT+IH+D8WGWrKaWWQTZGSoEjG/K3wwKQKgZIX8RwVfS3RGjmutDuO3dO5kc5E/E1XaWtLlItBxJQd/BwKyswJWd8s= X-Received: by 2002:a25:e051:0:b0:de4:6ef8:2778 with SMTP id 3f1490d57ef6-e02be16c560mr7307984276.29.1718933766611; Thu, 20 Jun 2024 18:36:06 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <2a6b92eb-d5e9-4a1a-9548-a068ac42ebd2@app.fastmail.com> <02ee8831-43a0-4857-886e-7f54fb42a99d@varteg.nz> In-Reply-To: <02ee8831-43a0-4857-886e-7f54fb42a99d@varteg.nz> Date: Fri, 21 Jun 2024 03:35:55 +0200 Message-ID: Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching To: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" From: andreas@dqxtech.net (Andreas Hennings) > Ilija and I have been working on and off on an RFC for pattern matching since the early work on Enumerations. I like what I see, a lot! One quick thought that came to my mind, regarding objects: Could we check method return values? if ($x is Countable { count(): 0 }) ... if ($p is Point { getX(): 3 }) ... if ($x is Stringable { __toString(): 'hello' }|'hello') ... while ($it is Iterator { valid(): true, current(): $value, next(): null }) ... Maybe it goes too far. For the variable binding, I noticed that we can overwrite the original variable: $x is SomethingWrapper { something: $x } In this case the bool return is not really needed. For now this usage looks a bit unintuitive to me, but I might change my mind and grow to like it, not sure. For "weak mode" ~int, and also some other concepts, I notice that this RFC is ahead of the type system. E.g. should something like array be added to the type system in the future, or do we leave the type system behind, and rely on the new "guards"? public array $values is array OR public array $values The concern here would be if in the future we plan to extend the type system in a way that is inconsistent or incompatible with the pattern matching system. --- Andreas