Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126186 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 BC1381A00BD for ; Sat, 28 Dec 2024 22:59:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1735426613; bh=Rwbz5WKOmg1AUhbBdibgUIZStD2fIyYAPOeVmeEkzcQ=; h=Date:From:To:In-Reply-To:References:Subject:From; b=WKUA4OznOhESjV7c8tC3XWii0psrWi4U3opq60qeKt+o09YSmD0F9rTUtvknRzN5M j+eVzRsef2lavOPu0m9e4EYTv7UqZ5XFsi+6bDmd0J+KZ+/CQKQjtsUhGODnvScI+k Wfyu/kKOERXbvkByGmAILtLLiFw0MV+KS3qFl9Jof6TMgNEVR+QNTiOpV5Ig0wQKfO 0uF4WT2ds12iCb636/rrE4t9qq2I2ySVA3weDSSKEFzwyiX6Q+u6VIinoxK+HD1dXK wYSsdNa61mpwdyr/ZFaYtjtMsIRynVmTMztA4VJbs/f/AGEHm/GqLmB0qan+i9U8O/ Dxjb8dehhsEBQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 16A3818003E for ; Sat, 28 Dec 2024 22:56:52 +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 autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-a7-smtp.messagingengine.com (fout-a7-smtp.messagingengine.com [103.168.172.150]) (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, 28 Dec 2024 22:56:51 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id C5A7A1380128 for ; Sat, 28 Dec 2024 17:59:49 -0500 (EST) Received: from phl-imap-06 ([10.202.2.83]) by phl-compute-01.internal (MEProxy); Sat, 28 Dec 2024 17:59:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding: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=1735426789; x=1735513189; bh=bTy5tWZKJRDwQs9pSSfAt pPhyWCTVLWBvuGBmluZ6Yw=; b=uRh9rGQ5w0db5fZqATlfDpfqWucleGaUTyKqW WLDjklJBpr1vKYril0pKLOoTzeGF03rjeGO4eAEDRw15fTjLini1r83BZQlg5Blq KQ8g1/DTdDlX7YfUYo13e00rb5lH9tb6NyYvmqiEA8QQXEaX2OSjPy3Y8GMQeJKT qBsYaXycn9AeGQ6vTbYR5FmWpXWZEVnRjrTk1mXsK4gO2x1O4+J2CpOp75xPHSqc +tiG2G1QEJcrHjRT+FVaKzov7GHNmqi211y53tyUW1oVcg8XhkVJeFECpG1rXWKA q0SHOCdcpVLFbaS145To9Ml0vkVwXyCZZTf1oFgFTMLRtI9LA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=fm2; t=1735426789; x=1735513189; bh=b Ty5tWZKJRDwQs9pSSfAtpPhyWCTVLWBvuGBmluZ6Yw=; b=XFJ9EwNgRftAhzYnS EoUhCtzvSsNXZXcXEiF6deox9Dubq7mfLQzgjGYlYhVMWgiQ/YdiSVcd6Cj/STG1 uXutbM1kHXMXRbyJg+Np/vfs891w3NUHXlSX5aGbX4npc6cpfF6CQ4ULBYTRzH5S VL4ZjU97kPXfjU71JBVfLllx7tJ1evkE0hmNMD88LULeie8ftqQYCta4CzZCQCme NtQXNPh9iqr/JDTOf4wnWOUdPPmQfd4Vyhd1CD0b3eiEgvcJ9YbOFmqi0xZunuw+ o6HyJs+aqMfgqxe21ISKkeXzYR431GsZao1RgBtLuBAtDmIqkDgUcTFFot26gRMI 4OA/g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddvfedgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepofggfffhvffkjghfufgtgfesthhqredtredtjeen ucfhrhhomhepfdfnrghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfih gvlhguthgvtghhrdgtohhmqeenucggtffrrghtthgvrhhnpeeffeffvdekffevgeeutdfg veefudegudegjeeuteetgefhjeeiffejhfegffdtheenucffohhmrghinhepphhhphdrnh gvthdpvgigthgvrhhnrghlshdrihhopdhgihhthhhusgdrtghomhenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivg hlughtvggthhdrtghomhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhht pdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 7A62429C0072; Sat, 28 Dec 2024 17:59:49 -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, 28 Dec 2024 16:59:29 -0600 To: "php internals" Message-ID: <430e1c1c-4cde-42f2-94f1-d9153239fd70@app.fastmail.com> In-Reply-To: <087a01db596a$e7525660$b5f70320$@glaive.pro> References: <087a01db596a$e7525660$b5f70320$@glaive.pro> Subject: Re: [PHP-DEV] [RFC] [Discussion] Optional interfaces Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Sat, Dec 28, 2024, at 2:56 PM, Juris Evertovskis wrote: > Hi, >=20 > I would like to propose a new syntax that let=E2=80=99s you implement = an=20 > interface only if it exists. >=20 > `class MyClass extends ?OptionalInterface {}` >=20 > If the `OptionalInterface` exists, the class implements it. If no such=20 > interface can be found, it is ignored. >=20 > https://wiki.php.net/rfc/optional-interfaces=20 >=20 > The need to declare compatibility with a certain interface without=20 > requiring the interface itself comes up when you=E2=80=99re writing co= de that=20 > should work with various versions of other libraries or PHP itself and=20 > when a library provides interoperability with some other library or a=20 > PHP extension, but does not require it. >=20 > Although this would mainly be used by library developers, the consumer= s=20 > of those libraries would also benefit as this syntax would clearly=20 > communicate the intention of optional interoperability. IDEs and stati= c=20 > analysis tools could also have easier time with `?OptionalInterface`=20 > instead of class definitions inside an `if (interface_exists(=E2=80=A6= )) { =E2=80=A6 }=20 > else {=E2=80=A6}`. >=20 > I=E2=80=99ve not entirely sure about the naming as an =E2=80=9Coptiona= l interface=E2=80=9D=20 > feels like an oxymoron. I=E2=80=99ve also considered names like non-re= quired=20 > interfaces, conditional interfaces, optional/conditional implementatio= n=20 > or even soft interfaces/soft implementation. Please let me know if the=20 > naming itself bothers you. >=20 > Previous discussion: https://externals.io/message/125967 > WIP implementation: https://github.com/php/php-src/pull/17288 >=20 > Looking forward to your feedback and suggestions! > Juris Going by the design/RFC, this seems reasonable to me, and I can see the = use for it. My only concern would be if the implementation makes anythi= ng more complex for the engine or compiler that could cause future optim= ization problems, but I'm not qualified to answer that. It may help the RFC to include some non-trivial real-world-ish examples,= in addition to the A and B stuff. (You can probably steal some from th= e projects linked to.) --Larry Garfield