Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125967 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 9DEA61A00BD for ; Fri, 15 Nov 2024 23:34:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1731713809; bh=QmEEsmuiUDHOh46xJftCJmfiavGbmd3+37iasmOyfgY=; h=From:To:Subject:Date:From; b=cBOVdpYmyuVzbGju7YFL5+nhGJasSFaK47whnAo/BNCNSMsmPnKR2evTfA1fPTZwX Od0/nvEN10i7jkNW17srAFEvuZ0Zu1vkbnSLdcky0H9Q3YjhaZeR3P1MFEc7fXgjb8 sz8IfVvIjvWbDlq0zpClznk1TPopzc0nTXBHw01pD2ezSdupztPmwrgKP6e9bU9o2z joaxvfB+9vw54+AKePPkcufcxic3/HFidNMXl1W+ykH+lkaVt/RoJt09geyQdyR2Yu XeJwUsQrdN/bfjgmA72KnJWkeZpOcjzgvmKuzkMk6cklsP1PDWpqmKrUT5t8WpMPmC 1OkxQG18RTcnw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5167618003F for ; Fri, 15 Nov 2024 23:36:48 +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_H3,RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,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 panther.cherry.relay.mailchannels.net (panther.cherry.relay.mailchannels.net [23.83.223.141]) (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, 15 Nov 2024 23:36:47 +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 6244D901C70 for ; Fri, 15 Nov 2024 23:34:09 +0000 (UTC) Received: from server42.areait.lv (100-107-243-58.trex-nlb.outbound.svc.cluster.local [100.107.243.58]) (Authenticated sender: yszpovajlk) by relay.mailchannels.net (Postfix) with ESMTPA id BEADD901B8F for ; Fri, 15 Nov 2024 23:34:07 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1731713648; a=rsa-sha256; cv=none; b=CK//zEQiWV5JONL0dIjrbh2fmCiNMjKPBjO0oVlzTvMAS4U7pNOBO38KPAAVehuhxrySlx vi+gXGDFMvdCZiyjhFUwcy1HJ8MbEQ01KJIjiyoA95PMgx8rdZGFWcTnVsK4vWzol+u7zs ua7AJJjPpI/vFfpOQqmPVSKFU0chktz0rl9buJoU6F+B9Cn+8Jz3JfOZMyMwWq855gTCNF c5sfEfZPoICGbwvPAg+lVGeg2enuCSrLkzVXDYRJf+VZy11l5/6nfmx8PnjYJJCpcRnhwu 8rmDnepbvl+jEocCbcBcI1TFIJAAlzkXu/ilDm2e6XC+meh2C/FBJHE946pRpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1731713648; 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=MCej/Eeabv79xrtBPkDYNeHZzGhFKVk8kKFm3WMgCC8=; b=j4qgI/StNHbeCVPxSnkfCrXhi9MCx6aWxipUfR8UiTMp5MzIWj/jZtTM4Qc2fySTMTTzC9 MIGNZ+vz5/4Ole6MJk4Lom9zf/lzOLJyB4nDmbcAIf+3+RYYtO6fL71zZmji1T5by9mdlF W9Qi2C7rUMPhIu59rxUBko1cxWH2nJ0Oc+Fu2ytiMAtvNs0GgI5BcGbd3w6UEnB0QdRhE5 XijgNgJ22+NUAKTniRwR57rkEXWx+D1hJITcOP3w0FmPT30A+x7jRpbBw8aWW7aWKO9ncb ifCJyp03QHdf9cx8s/K/Gi8nDOpGAejP0MIsi2Mpv4totkr0MjHsb2oN+0g+WQ== ARC-Authentication-Results: i=1; rspamd-645676964-z9bzf; 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-Tangy-Tank: 6008a0f327fa01b4_1731713648306_3467615974 X-MC-Loop-Signature: 1731713648306:1202456534 X-MC-Ingress-Time: 1731713648306 Received: from server42.areait.lv (server42.areait.lv [212.7.207.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.107.243.58 (trex/7.0.2); Fri, 15 Nov 2024 23:34:08 +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=VJcXrAPZamyKESXZHG6taW8bUnE+UmoPFT5HSQwwWPM=; b=CSveKoNxdV5hooMSfNoNEHLxZY wjg4nKQ4DQDYBOP2pj+qSjCwO57aKBdrjlhX9LghgoiaEgKevqhMQ5PmN3rULxmNOc8uQ1soRrA8G 5BUvGDrFy878uwI7iQQVX0sLtd80labjg2E3qqEwxqjK0w3pjnoudgh+89uscQfOAv/fFEbfpwqFz zJBO5NFaLxzuoHs7lxiWWSGLP86x9wKXya3kh8RLy4sM6d7rNr+G27+3LXxLRtGgACmAhuO1V/hf8 Xx46knH1+9rt7ZfTdNJjDoZhXQo8rRKPwDHiLGcvzYZnDhpsWQ9HogtHqjSVPTqVO88zowls9sdCF XiOcXR7A==; Received: from [77.93.29.116] (port=50645 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 1tC5pD-00DLmI-2S for internals@lists.php.net; Sat, 16 Nov 2024 01:34:05 +0200 To: Subject: [PHP-DEV] Optional interfaces Date: Sat, 16 Nov 2024 01:34:02 +0200 Message-ID: <0a2f01db37b6$daba4e60$902eeb20$@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_0A30_01DB37C7.9E439390" X-Mailer: Microsoft Outlook 16.0 Thread-Index: Ads3seKSqasvJDguQ6S5i5z/M/gowg== Content-Language: lv X-AuthUser: juris@glaive.pro From: juris@glaive.pro ("Juris Evertovskis") This is a multipart message in MIME format. ------=_NextPart_000_0A30_01DB37C7.9E439390 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hey all, If you try to implement an interface that does not exist, you get the 'Interface "%s" not found' error. Usually that's useful as it points to a code error. However, sometimes we want our code to be compatible with an optional library. For example, my Expression class might be compatible with some ORM, but it would also usable without it or with another ORM. This can already be accomplished, but the solutions seems very workaroundish: https://stackoverflow.com/questions/57996429/implements-interface-only-if-ex ists Maybe the PHP itself should allow marking some interfaces as optional - such that they are discarded from the list if the interface class does not exist? Here's one way the syntax could look like: class Expression implements MyInterface, ?OptionalInterface {} interface EventDispatcherInterface extends ?PsrEventDispatcherInterface {} BR, Juris ------=_NextPart_000_0A30_01DB37C7.9E439390 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hey all,

 

If you try = to implement an interface that does not exist, you get the = ‘Interface “%s” not found’ error. Usually = that’s useful as it points to a code error.

 

However, = sometimes we want our code to be compatible with an optional library. = For example, my Expression class might be compatible with some ORM, but = it would also usable without it or with another ORM. This can already be = accomplished, but the solutions seems very workaroundish: https://stackoverflow.com/questions/57996429/implements-= interface-only-if-exists

 

Maybe the = PHP itself should allow marking some interfaces as optional — such = that they are discarded from the list if the interface class does not = exist? Here’s one way the syntax could look like:

 

    class Expression implements = MyInterface, ?OptionalInterface {}

 

    interface EventDispatcherInterface = extends ?PsrEventDispatcherInterface {}

 

BR,

Juris

------=_NextPart_000_0A30_01DB37C7.9E439390--