Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125974 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 ACA7F1A00BD for ; Sat, 16 Nov 2024 14:36:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1731767928; bh=bFOCWdjnVIAlMiif/bNHb7XYSmHwuvH1FL7ZmAc0Fzs=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=YNEV2oGnjK9WQzVNHXPVjrUuoLEZSESAcc+nyXwrzjo4WlqpbARwXVVw7OGeVQla+ szKUCNuJPVbY6hv+0Npb4mWiBKLAfSyMn8qLCJGDV333iqeCPXr22a1KBpgSVocCtG x+4145BW21Um8KweZu3tB67oxT+gMwdyhD9kZahh9Nj/WpF5u7pBJweZi/AayTbVwX ftj/4Cf2QERWt01Fla8dDBNT31zuDW+XcZGv6KXfis7atZ+7SYufzVMP8zr7ZpsKVR 38Img/3sZ3EzvKnwH44Uf88o55nxRYGMj+or8yr06JRNsavyxG3HAVyD3LCdVv96R4 CWvxYN9rNYHNw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ECCA218005B for ; Sat, 16 Nov 2024 14:38:44 +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,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.144]) (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 ; Sat, 16 Nov 2024 14:38:44 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfout.stl.internal (Postfix) with ESMTP id 10F651140121; Sat, 16 Nov 2024 09:36:06 -0500 (EST) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-01.internal (MEProxy); Sat, 16 Nov 2024 09:36:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc: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=fm1; t=1731767765; x= 1731854165; bh=bFOCWdjnVIAlMiif/bNHb7XYSmHwuvH1FL7ZmAc0Fzs=; b=p 8PZZ2D6uzZjlaDvl5nDvKfFaJp4WZ22/qeIaWyzJEBNoSKsDpvBaaoDI5VxQ1cWX TQcJuBLES1AV0qaE9sS4nhA4IJppavFk1fh7WQoEiV4zCvNUGBo2Kl+um9zYrlVJ pkR4h/pLpJKipi+YfZMIpa2AG54x5jxdncTx57MNJDpM6KBLg23Hal9Dd0SqDPLQ R1VzPVv6pYGDaVIUKgNEsgJYHOOToUvlJFMRlA7v62JwQjFwQplrbkkNsCxDIn3I 4l4Y0O3kabwK8hE8A/fBxDlAgAo4ZqXrpBf7qKQioPNhn8eLn5+rqoiQh3XIqzHi AqQyk2zJiSlO6YgOXOwnw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1731767765; x=1731854165; bh=bFOCWdjnVIAlMiif/bNHb7XYSmHwuvH1FL7 ZmAc0Fzs=; b=VABbreIg8lRX/EJcM6RabaTNdQXfVVA0DXEThSBI2x/BNJL5LQl qgY+SYRPS9QTsAEgwlr4O+ZBI0u7E3bI85A9n3QeBjfSC+FtwzBcFl/dcgRrRtrB s9aaJ6xkvLpcG1uIbXP/Js86ktlIsGZ8Ue3XswPSCeWeI1iG99mKkjPMxQDMdQSi CeDQGYQiOrJhU/RWr/570OuocX0VYjTNiAqSSgf+IBtkxlseREEx0SW1JQOcgCpR Cp6KLph7Lkc/T+9w10iMgUTaAjLYD8WaA3gIBqhPZzztEE5KQrt8hhwrF2dwjGp+ 1jfkuZ89Jil2YKUJuHYLoGkcIZZVg2l+bZQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrvdeigdeigecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenogfuuhhsphgvtghtffhomhgrihhnucdlgeelmdenucfjughrpefo ggffhffvvefkjghfufgtsegrtderreertdejnecuhfhrohhmpedftfhosgcunfgrnhguvg hrshdfuceorhhosgessghothhtlhgvugdrtghouggvsheqnecuggftrfgrthhtvghrnhep hfevteevuefhjeeitdehhfevgedvvdfgudejvedukeffhfehvdfgffegvdelfeffnecuff homhgrihhnpeefvheglhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggprhgtph htthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehuuggrlhhtshhovhdr vhgrlhgvnhhtihhnsehgmhgrihhlrdgtohhmpdhrtghpthhtohepihhnthgvrhhnrghlsh eslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 6AAC7780068; Sat, 16 Nov 2024 09:36:05 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Sat, 16 Nov 2024 15:35:44 +0100 To: "Valentin Udaltsov" Cc: "php internals" Message-ID: In-Reply-To: References: <0a2f01db37b6$daba4e60$902eeb20$@glaive.pro> <002c01db3806$383ad2e0$a8b078a0$@glaive.pro> Subject: Re: [PHP-DEV] Optional interfaces Content-Type: multipart/alternative; boundary=bd1979a9c3a147a0b35933eeab37be21 From: rob@bottled.codes ("Rob Landers") --bd1979a9c3a147a0b35933eeab37be21 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sat, Nov 16, 2024, at 12:43, Valentin Udaltsov wrote: > On Sat, 16 November 2024 at 13:42 Rob Landers wrot= e: >> __ >> On Sat, Nov 16, 2024, at 10:02, Juris Evertovskis wrote: >>> Is there some reason you cannot do this: >>> =20 >>> https://3v4l.org/hF1vr >>> =20 >>> Unless I=E2=80=99m missing something, you can=E2=80=99t patch-define= a namespaced OptionalInterface that easily. >>> =20 >>> Anyway, I was not implying this is something impossible to accomplis= h. My point is that it would be beneficial to have syntax for expressing= =E2=80=9Cif your app has this interface, our class implements it=E2=80=9D. >>> =20 >>> Juris >>=20 >> Yeah, I get it now (see my reply to Marco). >>=20 >> Even with namespaces, it is pretty straightforward, though: https://3= v4l.org/dmXoB >>=20 >> =E2=80=94 Rob >=20 > This is a nice solution. >=20 > However, interface_exists should be used for interfaces. >=20 > -- > Valentin >>=20 Actually, you'd probably want to check for both (as well as traits) for = a better developer experience. For example, using interface_exists results in the error "Cannot declare= interface, because the name is already in use" if a class with the same= name is used instead of an interface. This is a nonsensical error messa= ge because the library is not responsible for declaring it. Instead, you'd want the error message to be more actionable: "cannot imp= lement class -- it is not an interface" =E2=80=94 Rob --bd1979a9c3a147a0b35933eeab37be21 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

=
On Sat, Nov 16, 2024, at 12:43, Valentin Udaltsov wrote:<= br>
On Sat, 16 November 2024 at 13:42 Rob Landers <rob@bottled.code= s> wrote:

On Sat, Nov 16, 20= 24, at 10:02, Juris Evertovskis wrote:

Is there some reason= you cannot do this:

 

 

Unless I=E2=80=99m missing something, you can=E2=80=99t patch-defin= e a namespaced OptionalInterface that easily.

 

Anyway, I was not implying this is something impo= ssible to accomplish. My point is that it would be beneficial to have sy= ntax for expressing =E2=80=9Cif your app has this interface, our class i= mplements it=E2=80=9D.

 

= Juris


Yeah, I get it now (see my reply= to Marco).

Even with namespaces, it is pre= tty straightforward, though: https://3v4l.org/dmXoB

=E2=80=94 = Rob

=
This is a nice solution.
However, interface_exists should be used for i= nterfaces.

--
=
Valentin
<= br>

Actually, you'd probably want to check for both (as well as trait= s) for a better developer experience.

For examp= le, using interface_exists results in the error "Cannot declare interfac= e, because the name is already in use" if a class with the same name is = used instead of an interface. This is a nonsensical error message becaus= e the library is not responsible for declaring it.

Instead, you'd want the error message to be more actionable: "ca= nnot implement class -- it is not an interface"

<= /div>
=E2=80=94 Rob
--bd1979a9c3a147a0b35933eeab37be21--