Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123767 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 48A491A009C for ; Sun, 23 Jun 2024 19:14:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719170162; bh=R68OAWyKiqu9BvE+dAe047rXUrHoRlw/waCu/C92AxE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=jc8K4WVuhWofV0QSFRn/tflkilEAScDDUAcJ4tXfkSyIaeZ1bwVqE/Oj4ttsybMhx HdJtrggOkvVPKLY6ax+WVyoKMmhxkvq9fVY3cZJPSPcSW2UHI/T5roOWA2hbVbHTLT KLw/zUGnmKycN2adnhQ1rGGTKicMPY5E9YO7A0lh+wlhAMTQsBDsCwy7EHbwkj049Z GUtckiVpbohTQV+ytxNYb5OpH2FQbjXASZnQyCtUqiALXSgGcN158rz3bUXliuAQSd Q7fV0htLqWi9wTguxSK8JwrnaKfl6TUrXxG8G9UFOPmhLRMvXD5U0kMoFsLrc1VE8x YcZqFF0rWEwSg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E1AD318057E for ; Sun, 23 Jun 2024 19:16:01 +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-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) (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 ; Sun, 23 Jun 2024 19:16:01 +0000 (UTC) Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-dfb05bcc50dso3145783276.0 for ; Sun, 23 Jun 2024 12:14:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech.net; s=google; t=1719170085; x=1719774885; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BOsCaFARZhgV1SbuauHidutUJ88aZZGuoLCkSVJOHw0=; b=EqkoE9G7T2MN4EpSsdSZtqHPG7q9aiBGdtEr1jVUJlcq0aaGKZKUPn6VWtxkiQGvkT nUadbqytTcXCPSd2a6ICKusDngQziQpmu83kc3wIvfb1mXcRCPOZHMFY+f+evG/OItuT uoYGBWFU7nZpKa/93FFhRsJYvXqLo2RAxRx7Rz7u0IkLiACpgsEwwQrewkk5Gvznv8Tb r8fAjQZzWLKleL33eokZtL4uwWmfPt12mvDf0Qb3mML1rejeXlsKxWH2g9mxDl6Zp5Gt x2LsmDWMEHxYe3TrdEOpj3rTbyNjGMeA1IanVxhIKct0JRiQZnKtALAPUfM9wet02P6p BaCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719170085; x=1719774885; h=content-transfer-encoding:cc: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=BOsCaFARZhgV1SbuauHidutUJ88aZZGuoLCkSVJOHw0=; b=htjpv1lDfecDL4OwJd6BlNmlrWa1RLBNRmsYOCcduMh2XPYFVHQQYvIqBhi1/3qn0S fqj+jvXg+Tr36Lm7WeyKHAxKtKTlid1IBzB7pHAO3fEv54e76LfGFxsnKMF2MK9twyNm teJxYG2P4f2SvLlOot2VdnZ1AHz7P9ghtA429myTyT4sM6upAklYQKKcm+wdCD709gyN fTNeGgAwzsY9BRMachviEsdcXB+w7G2NpBDT6WLvB5MhvD2K8f6ZVWF4IXCEk3ARh8eb nvvbFONAqzPbrMc15n0eVHDezWC/v/Ex/cQxR4yztiTrkFrAyMErkJV0bZlmYWj/JzsV XaEQ== X-Gm-Message-State: AOJu0Yx0K3yNxVazATgPXnI5ENUErgZ8SJJCMV92FY7CmcJNgXgrPyFs VUQ43qVDB1KdQJLvsdFEAwjVl8bghkc0kb/VJowzK8waluzDQ7Y5py5IUOjZvpfPkgn106FV7Pi P8/+1M/81Dpz+sxKnowPu78q/vBrB40Ci2/3ZT8AI2OUreg9l/M8= X-Google-Smtp-Source: AGHT+IEsTkqysnTcawS9LzUVJii3ZxKDcv9QpTokNsKAALiY0IlnKOzlUEHbmgT9s57v1HS9+43kky4ruagfP92Yu24= X-Received: by 2002:a25:ad56:0:b0:dfa:4ce2:3311 with SMTP id 3f1490d57ef6-e0303f4831cmr2403420276.39.1719170084895; Sun, 23 Jun 2024 12:14:44 -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> <7c9e97d3-3d3a-4e91-9eeb-2d460310befa@app.fastmail.com> In-Reply-To: <7c9e97d3-3d3a-4e91-9eeb-2d460310befa@app.fastmail.com> Date: Sun, 23 Jun 2024 21:14:09 +0200 Message-ID: Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching To: Larry Garfield Cc: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: andreas@dqxtech.net (Andreas Hennings) On Sun, 23 Jun 2024 at 18:28, Larry Garfield wrote= : > > On Thu, Jun 20, 2024, at 8:35 PM, Andreas Hennings wrote: > >> Ilija and I have been working on and off on an RFC for pattern matchin= g 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. > > Much to my surprise, Ilija says that's technically possible. However, no= w that we have property hooks the need for calling a method is far less, so= we'd rather not in the interest of simplicity for now. A future-RFC could= probably add that if it's really needed, but I don't think most languages = support that anyway. (Need to verify.) > > --Larry Garfield Even if property hooks will be available at the time, a lot of classes will be from other packages that use getter methods to communicate. And, even with property hooks, there will be use cases where getter methods remain the preferable implementation choice. But ok for me to push things like this to follow-up RFCs. This leads me to a different question regarding property guards. What if we validate an object property guard, which later changes? class C { public function __construct( public readonly Point $point is Point { $z: 0 }; ) {} } $c =3D new C(new Point(0, 0, 0)); $c->point->z =3D 5; The second operation would violate the guard condition. However, I suspect that the operation will not trigger any validation for a guard where the object is referenced. So it would be up to the developer to only use this if Point::$z is readonly, or they cannot rely on the guard.