Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126185 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 8E6851A00BD for ; Sat, 28 Dec 2024 20:56:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1735419189; bh=+FXfepKdACN9MSO1O+QNAftieUtc+E0Rx5d/lYKr3tk=; h=From:To:Subject:Date:From; b=EWSxNDSSW87ynb9Y7s9yJ67sOz4SqF6zIGkAvVd2lxuAWnRBs/aw6IgUYHfYp+IIG VS2tw7NI47r334P1Uh7EMu+X4B7ZWDp0IHhkv07YxX1bhHNI6xYdHAsQdfSquXgLBr aqCvawGKzQ5+sZCq0PL2EANzxTTbO64cOz4EOFmpdinWepKxdr5PwO8altHEcT/U+4 kapB+Xhdinuz12aVIJXQDd04qzZQzfZymMnmBjA4dYrrttcSruyEkP8uNh8eVpw6xu 8S0tp1OGGP2lQ8xbXCGhoff0Dx7KVS0Z2fntKGVNfiApZNPdLFIFSdyn9AxiK/j4/D ncZ3IoOquMH6g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6F4F6180054 for ; Sat, 28 Dec 2024 20:53:08 +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=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_PDS_PRO_TLD autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from buffalo.tulip.relay.mailchannels.net (buffalo.tulip.relay.mailchannels.net [23.83.218.24]) (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 20:53:07 +0000 (UTC) X-Sender-Id: yszpovajlk|x-authuser|juris@glaive.pro Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 50B2B78258A for ; Sat, 28 Dec 2024 20:56:06 +0000 (UTC) Received: from server42.areait.lv (100-109-23-148.trex-nlb.outbound.svc.cluster.local [100.109.23.148]) (Authenticated sender: yszpovajlk) by relay.mailchannels.net (Postfix) with ESMTPA id 13C357824D9 for ; Sat, 28 Dec 2024 20:56:04 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1735419365; a=rsa-sha256; cv=none; b=Zxu14csSZk/u8qb0JeUuO28eRxyruf3UoSKD5BatR8wgorSp9losZmyCPZMBgRYa4zlK4J rVyjgsgezpaGiFhHyieKnbxUVy1oKVLYqeTKft3CiZfj5NG0jbJtLf0B3zRdH94gmxSxke KqOHA9m9rpk8z6xXLdvi7rDK1LMf8UWxD0PSueUSomudUhb7FvS5UoPa1qle+X+XJmH00V bUSecxeyWXShzY4palKMjopfhhy9bns5WzE07kWoq+9sSgwiVxnhtuI+xDDwYuqGXWBW4T ZGjo25GIkH8dwaiegibIryMnGRRxsAGpA++vjwoQy+o3zs9AROSAaeXYCizYUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1735419365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: dkim-signature; bh=b20oD3LD9tJ6SnRUQNnXqDrkzxXVqm5JodLMKVppPk4=; b=POy1VBHnDNdqJVPzOW7V6zJhvli+k7yRB5D9OUBDf+o3Ngsgnb9v9VSjtQ4N7icvx0FIOR ZdnHzZUhk2RhLY53la3O7F7xlQQn6t8qFzp1Y30KbRV9tjZSQu0CRI3wPWwHxdQv6wHwWS nk4Leu67ER4NWZdvgkWhBYHGRhOnVFl0V76jpCnj7iLGrUsVl465jJPJY9eTkQ5QjqOBlv RjQ2LKSlO1iQK7+Ct8fGPUgmYrt948zVjWzaMq+BtdLFy8ODmd4GNzEUEt2qud1ZG5jHcZ Hr2g7ABRdAQ3U+PHDxdqH9N1szfSlJ/RdpxQhGKGmpYW458xcT6wyIfVhtKChg== ARC-Authentication-Results: i=1; rspamd-7d788bbf85-49qjh; auth=pass smtp.auth=yszpovajlk smtp.mailfrom=juris@glaive.pro X-Sender-Id: yszpovajlk|x-authuser|juris@glaive.pro X-MC-Relay: Neutral X-MailChannels-SenderId: yszpovajlk|x-authuser|juris@glaive.pro X-MailChannels-Auth-Id: yszpovajlk X-Decisive-Macabre: 2610bc0445cb6f4a_1735419365587_3664626735 X-MC-Loop-Signature: 1735419365587:3231705841 X-MC-Ingress-Time: 1735419365587 Received: from server42.areait.lv (server42.areait.lv [212.7.207.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.109.23.148 (trex/7.0.2); Sat, 28 Dec 2024 20:56:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=glaive.pro; s=default; h=Content-Type:MIME-Version:Message-ID:Date:Subject:To:From:Sender :Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=NW77HgRNqNDTf9MSv2ZwDU0T6hxHE6eWvgCuIM8sE/E=; b=EAFYXud2d1zo+tcpUxGR2qKJPF u8RU9iJp2AQKi2pA1a8Pzq//QSS5Ew9JvzXGs8EHrjHmMs/kiNlkOJdT2WFt3Rti+akJR5iZVMGsE doQvLkO5pP74JG110Xg1cfQ3jxwUPaW0Xus7ELjjFJltNGkAa9/8R7vLs4TO4RyhBPSUYXPODkJSM FGDDasmzhUnPnOlw7/C+UbTnfYOUyHq+p1zml53xirqzpfNDQjDs23j2UOpD/V3D2O5nAxoYlFXKH 0cMmt2fA1rZSWsnswVbrZNTkDns34rH6BicEUAAcqj5GzR9QWvXU+cn9M0/RRtECtx7LYc0+aWwnZ QPlIUvFQ==; Received: from [77.93.29.116] (port=62569 helo=LAPTOPHKIOPCGI) by server42.areait.lv with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1tRdqr-0060n4-3C for internals@lists.php.net; Sat, 28 Dec 2024 22:56:03 +0200 To: "'php internals'" Subject: [PHP-DEV] [RFC] [Discussion] Optional interfaces Date: Sat, 28 Dec 2024 22:56:01 +0200 Message-ID: <087a01db596a$e7525660$b5f70320$@glaive.pro> Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_087B_01DB597B.AADBE9B0" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdtZZwQ+ZL7bhOMTQq+Ic97vKKjs2Q== Content-Language: lv X-AuthUser: juris@glaive.pro From: juris@glaive.pro ("Juris Evertovskis") This is a multipart message in MIME format. ------=_NextPart_000_087B_01DB597B.AADBE9B0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi, I would like to propose a new syntax that let's you implement an interface only if it exists. `class MyClass extends ?OptionalInterface {}` If the `OptionalInterface` exists, the class implements it. If no such interface can be found, it is ignored. https://wiki.php.net/rfc/optional-interfaces The need to declare compatibility with a certain interface without requiring the interface itself comes up when you're writing code that should work with various versions of other libraries or PHP itself and when a library provides interoperability with some other library or a PHP extension, but does not require it. Although this would mainly be used by library developers, the consumers of those libraries would also benefit as this syntax would clearly communicate the intention of optional interoperability. IDEs and static analysis tools could also have easier time with `?OptionalInterface` instead of class definitions inside an `if (interface_exists(.)) { . } else {.}`. I've not entirely sure about the naming as an "optional interface" feels like an oxymoron. I've also considered names like non-required interfaces, conditional interfaces, optional/conditional implementation or even soft interfaces/soft implementation. Please let me know if the naming itself bothers you. Previous discussion: https://externals.io/message/125967 WIP implementation: https://github.com/php/php-src/pull/17288 Looking forward to your feedback and suggestions! Juris ------=_NextPart_000_087B_01DB597B.AADBE9B0 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi,

 

I would like = to propose a new syntax that let’s you implement an interface only = if it exists.

 

`class MyClass extends ?OptionalInterface = {}`

 

If the `OptionalInterface` exists, the class = implements it. If no such interface can be found, it is = ignored.

 

https://wiki.php.ne= t/rfc/optional-interfaces

 

The need to = declare compatibility with a certain interface without requiring the = interface itself comes up when you’re writing code that should = work with various versions of other libraries or PHP itself and when a = library provides interoperability with some other library or a PHP = extension, but does not require it.

 

Although = this would mainly be used by library developers, the consumers of those = libraries would also benefit as this syntax would clearly communicate = the intention of optional interoperability. IDEs and static analysis = tools could also have easier time with `?OptionalInterface` instead of = class definitions inside an `if (interface_exists(…)) { … } = else {…}`.

 

I’ve = not entirely sure about the naming as an “optional = interface” feels like an oxymoron. I’ve also considered = names like non-required interfaces, conditional interfaces, = optional/conditional implementation or even soft interfaces/soft = implementation. Please let me know if the naming itself bothers = you.

 

Previous discussion: https://externals.io/message= /125967

WIP implementation: https://github.com/php= /php-src/pull/17288

 

Looking = forward to your feedback and suggestions!

Juris

------=_NextPart_000_087B_01DB597B.AADBE9B0--