Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126188 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 EDB041A00BD for <internals@lists.php.net>; Sun, 29 Dec 2024 12:28:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1735475127; bh=gEmI4oPNqx5I6NpqjXJyF55QraBWanzB/h3R43qLB78=; h=Date:Subject:To:References:From:In-Reply-To:From; b=aCd+FY1M2m7ibfC2NW5+uJ/jc/a1ERPMu3GQ4htNpFphUrhBt/aOCKO3n2xlQWg6e 9XDsruRCRs3e0iSrPBA52K7zAPgGMKDh8pVzZPHBNsf5uDs435C5NDIjkBuitZepyr yLEt/CZ4JAnMf8e3SLzEUfvjTIxBH6frkPhLA0mnCiNOcvK6+DuFb7iXE0LjVFskO9 NOUEPi0gmRfNSTWjlJfuLMj/xp6An1qgW4d/+ReXVXQT13GSXJkIvO+Wb1aUk0O2F8 UTetCUHuQw9gARQYKDZfaLr8A2Nwuaty75kvICxHey2/hT+ULc7XGl4g62nH+bjD4m qWQ07tIHL0ZHQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8B386180071 for <internals@lists.php.net>; Sun, 29 Dec 2024 12:25:26 +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,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: <dossche.niels@gmail.com> Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 <internals@lists.php.net>; Sun, 29 Dec 2024 12:25:25 +0000 (UTC) Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4361fe642ddso89335515e9.2 for <internals@lists.php.net>; Sun, 29 Dec 2024 04:28:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735475304; x=1736080104; darn=lists.php.net; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=8TnFoNHQDyNuxBiLj5sPSEHcOPIbr9wLGFlNcPDlpD0=; b=A/Ips3tsCC0GVXtoyA9HqXTQ557cDi4PLme/34BKXUiICvKJUpyEkFb0sRHbygDIp2 yd4L2M/6g8CrOJaLVuB9TWTSLgq0YmXheOuAuut+H4sUTo2adEM3EqkeM2txh7EiRD+y 5XmPrFYdXyLn1y6DQKODhWkDVDX7NX2qQF78S8IsLofNF62HLXhBeygD3CuN6PGHrhkT eoquiZkSiO1Xkr2BBtoLfsnDJRjlBH4mzQemP3DvqUR7DJ4wKCaN+gIaTXG5vbhItZgM QblMe2R3xk336xmnKtiY8czY33WSpEhQHNrEuU/3DNu7xudqdjkmGDX51AW80h3HuEXH 9iRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735475304; x=1736080104; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8TnFoNHQDyNuxBiLj5sPSEHcOPIbr9wLGFlNcPDlpD0=; b=PxdaQzCeFxjJfTmoLkxogwPmLzxTo4KRfC/blqo6/uC1Mfqs0apaSj4IJpgxkkNkuZ joM3AyfZtZI5aqjtithjrlJgNkFetdW41FGLWUsodQl1qK+N/1+iAOO9m7KAGiB2ez1+ pArEvbPbbztcPCY8tiOa0merhwLFu9EGynfkTRyJ/wHwUdtdiZLrJHPmtXCYPd3nb+ND YzpcBjf7Q73DvyU2SHzBpYNb1jgw32sFLGrjYPNdxw2o17D2qJm43/p1Ev+UFZw+n0UY TMef24tPMy6bnuSfgg0A7HPqP5Y/loMVdU0P4i763F7EtF4/NHsPLvMFBFbzAt5dkXAV i6Qg== X-Gm-Message-State: AOJu0YycSx+PUyGnuU7a83p80uj7Jbf9kKRPcr/Ygg1d8eD2taMvdXyv svMJyvfg3qnARMwZIPdF8gvZROrig+EkxiuhZZwUWWbYbtUwRP5oJchkpA== X-Gm-Gg: ASbGncvDzgdd1WoYpiG2DZMvkmyajbAWUZn4m1ikfAsHgnpY3jknS2ksB0L8ApfjVMY 616stvd+ilu9nrxgm8WxoqlClME39oVBSsCwjadsOXh29JMggZ6UUYt2hioAQwUICJab3ZTPBfu o1f3PRt9tQHJj3CaYH97zv/IZwXIXefTqIF7b0N0yKZIajJNvqG/pFK3DKdDBut0UxLU5izOoEC mWjqijtQ1mrWNFZc0DbOnh9GBJ11bwlEe1jHT34kEGHoGyfOjPjCOeUONDXeLTNOrlT9lSgGHTs KusNPI8/VuRcGIO8LkOmTi+G5hT3ru6m/nvAnVMZFUMIP15+3UmACnhyDnCloGwxu/isEdqs7ng BVXEBYyrlUgWE25PYsC/v X-Google-Smtp-Source: AGHT+IFCFdIACm43JOkdpRjYRq7doxbxmx0IDy7L/qSlGSqv6zfXxLQiFEU4xPxCap8kBn4gm6yFyQ== X-Received: by 2002:a05:6000:470c:b0:385:f5c4:b318 with SMTP id ffacd0b85a97d-38a221f9186mr24220533f8f.31.1735475303831; Sun, 29 Dec 2024 04:28:23 -0800 (PST) Received: from ?IPV6:2a02:1811:cd2f:3500:e093:fcad:4f6:e542? (ptr-du5vm7f5ekzptmf0fgi.18120a2.ip6.access.telenet.be. [2a02:1811:cd2f:3500:e093:fcad:4f6:e542]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4365c08afcbsm334051085e9.21.2024.12.29.04.28.23 for <internals@lists.php.net> (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 Dec 2024 04:28:23 -0800 (PST) Message-ID: <f44f2387-62cf-4c72-ae23-e4d7979f1c8f@gmail.com> Date: Sun, 29 Dec 2024 13:29:35 +0100 Precedence: bulk list-help: <mailto:internals+help@lists.php.net list-unsubscribe: <mailto:internals+unsubscribe@lists.php.net> list-post: <mailto:internals@lists.php.net> List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] [Discussion] Optional interfaces To: internals@lists.php.net References: <087a01db596a$e7525660$b5f70320$@glaive.pro> Content-Language: en-US In-Reply-To: <087a01db596a$e7525660$b5f70320$@glaive.pro> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: dossche.niels@gmail.com (Niels Dossche) On 28/12/2024 21:56, Juris Evertovskis wrote: > 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 <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 <https://externals.io/message/125967> > > WIP implementation: https://github.com/php/php-src/pull/17288 <https://github.com/php/php-src/pull/17288> > > > > Looking forward to your feedback and suggestions! > > Juris > Hi I've left some remarks on your PR to help you further with the opcache stuff. This should fix the tests and answer some questions. I also left a concern regarding the caching, and in particular I'm thinking about the inheritance cache. I'll copy it here: Suppose this scenario: 1. You do a request and an optional interface is not available, this class is cached without that interface. 2. A future request comes in, and reuses the cache, but since this may be via a different code path it's possible that the interface is now available. Yet because the class was cached, this won't implement the interface now even though it's available at this point in time. I'm not entirely sure if this is a real problem but it should be checked. I also don't know what assumptions in the engine this may break. Kind regards Niels