Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123740 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 408F01A009C for ; Fri, 21 Jun 2024 18:03:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718993103; bh=vRu4DCUsq5aPwQS5vPE4PsiSkpk6aDcHbomed78iQA0=; h=In-Reply-To:References:Date:From:To:Subject:From; b=QwIssHfjD0blZ2IIo7Rr/OHYypzl3a/WkjhuvSF7qfAIggHdmRBvdkn+nOkqNhUR8 GJ+FgTFCnI62XpCFOLhPz/yt9xL5kUYGp85fCrpMRkUm0RGAnCXmPFRpjMDgKZw14h V7zXNtVnY6wlLx//NAV8vikO99O8eOnuwagRupuluUxexaArepX+lut+0h0LoruQh4 yD9FYd2GM6s45UFBAxVhBB8rMwse1bfpbztlM3yg7s/LikOOd2KDLqRUfRABN5xvkx YIg5/hkwNTkne4bbWvG96kNeCjS0GX2QC3NMAKaRml+YtI5xWjNpMpt6z0WjkvLDrK Sl/Xq6WABglTA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 79E271804FE for ; Fri, 21 Jun 2024 18:05:02 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE,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 wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (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 18:05:02 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 79BA51C0008D for ; Fri, 21 Jun 2024 14:03:46 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Fri, 21 Jun 2024 14:03:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1718993026; x= 1719079426; bh=B0AjSHqmq12EJlke9hpurp34nHYjBmVUOopGIQOW8so=; b=A EOo9+F1rCXKdsItiuIAupzOjr1eScLPA5NOsHHi0yltBVsdW//9RiVdLs9WW1NnO CoQ78mvegkgfp9AfeNqezpi5spHSMc61yqEptq/LANw/qY+ZLpqGxp/sWo3aZFAD ifqzaFKitaxhL7p+Pix6xIb+bwT3vQW/qsN1vWLYuiib4TkiDR7V579oyym5eCM6 +1X0Zjjhr4lgaCbjYMN5zrddWdpzIQmy+hAJ79dv1Y2u1x+cp0PuXi7AIISCUzmC P18wIILAB0aX0RrOrbCWi8x+4uTb0UUK86Mzm3NvcnvpaKVPKQEkH1vK6r7PGAFW Jl2MSFMPWVC6eo1FSQdKQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1718993026; x=1719079426; bh=B0AjSHqmq12EJlke9hpurp34nHYj BmVUOopGIQOW8so=; b=ahh1CUHfz/z67FcPK5+1U4tAReqZcnUFbe9pyBYAesQd UIbV9WgKSLX+vlE6lhVZjoFDfaJeODhw2ReanJSuSzUw+YDI+plAD9VGtNSAl1fL b5Rfs/RQ2CWjU/E/dXz0v7Dzk/zormMs+I5OVozVwjanbdjN5NxE2GIvKJ+QkVHq ea5cRTEyykOeZfcSgBb0JencWg1IauEnLEsWygk95nB4mSmp/c1WtvFQjmtwKREB zv+M1eUkgj6XTj8c6cyfBSRePrdI0F7LS1Air5e8FU1DkofMSOddg3Ci0kOi7n/W dgDaaPg3voKvPFnGtvhtle/2NWwrOKtItg3IFuaUBg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeefgedguddvudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepgeelgfekudeivddvteffueejffdthfejieevhefg ffekudevkedtvdelvddvffefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id B0C151700093; Fri, 21 Jun 2024 14:03:45 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-522-ga39cca1d5-fm-20240610.002-ga39cca1d Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: In-Reply-To: <7ec12de5-b2f7-481c-acca-1b38f5be7deb@mabe.berlin> References: <2a6b92eb-d5e9-4a1a-9548-a068ac42ebd2@app.fastmail.com> <7ec12de5-b2f7-481c-acca-1b38f5be7deb@mabe.berlin> Date: Fri, 21 Jun 2024 18:03:25 +0000 To: "php internals" Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching Content-Type: text/plain From: larry@garfieldtech.com ("Larry Garfield") On Fri, Jun 21, 2024, at 3:57 PM, Marc Bennewitz wrote: >> Thank you all for your participation. > Is is already a really nice RFC, even if not finished yet. Also haven't > fully read it yet. > Thank you for all your work and time put into it! > > I do have some questions: > > * For the generics-like pattern I do agree with the others that this > might be dangerous for the future if we (hopefully) are going at it. I'm unsure. As noted in the introduction, a pattern may look like some other construct but is not that construct. So `$a is [1, 2, 3]` is not actually creating an array, for example. That means using array should not, at the engine level, cause any conflict with future generics implementations, should they ever materialize. It's really just a shorthand for foreach ($arr as $v) if (!is_int($vl)) throw \Exception; Now, whether or not it would be confusing for the user is a different question. Array-application is not part of the critical path, so if the consensus is to hold off on that for now, we can. (Answering that question is what this thread is for.) > * Capturing values out of a pattern and binding them to variables if matched. > > Where this is very helpful especially with `match`, from the syntax I > would read it as a condition only. > > $p is Point {x: 3, y: $y}; // read as $p->y === $y but it's $y = $p->y > > But this is described differently > > $p is Point {y: 37, x:@($x)}; > > > I think it would be more readable on switching the logic (somehow). like: > > $p is Point {x: 3, y: $y}; // $p->y === $y > $p is Point {x: 3, y:=> $y}; // $y = $p->y There was a bug in that example that I fixed this morning. It's now: $p is Point {x: 3, y: $y}; // If $p->x === 3, bind $p->y to $y and return true. Please ignore the old buggy version. :-) > * Regex pattern > > This one is interesting as well ... but I would expect native regex > syntax first before introducing it as part of a different RFC. Similar > as generics. Named capture groups are already part of regex syntax, just not often used. The example is not introducing anything new there. (Although Ilija tells me it may be hard to implement, so it may get postponed anyway. TBD.) > Following up I would expect something like this: > > $re = /.*/; // RegEx object > $matches = $re->match($v); // preg_match > $v is $re; // used in pattern matching > > which opens up another question: Could we have an interface allowing > objects to match in a specific way? > > interface Matchable { > public function match(mixed $value): bool; > } Oh my. I'm not sure how feasible that would be, or what the implications would be. Definitely future-scope at best. :-) --Larry Garfield