Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127457 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 lists.php.net (Postfix) with ESMTPS id 673171A00BC for ; Sun, 25 May 2025 21:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1748207749; bh=qKJX04v2awZQM+OZ5sYQmtG80mbQIttsPj15LF3jI/0=; h=Date:Subject:To:References:From:In-Reply-To:From; b=QngnPVxUFYsGEvIFj+w+JmiONLK7RchhJkFdgJj2MxCsFFOiKzVWjRGo7iP7aIHv0 9xISveh8WcgS5EW/2KiVG9pKNkx1VgNRWjgv0efy5Ej0vRRXtn6IAqXGfuxNAblaJm uayflCCwwv3qJKpfwOYUNVOAFl2PTxGJIIZhdvjwHJfWZCV28XVMZIZh1iJ37zLeVb Szgy1Rf0o0ABsYlDg5S7Vw19Y2ZUF/5ttxYyHwgxVcCps0Bwtf4Xb7Gq9G5Sq6WQzf dAmJgZE+bD8N0hdgtum39Wvq7FIirhzlNf4ol7sGAj1mE5hYBMewL+4zj21sHaG0Tt qYrFTWyJmiSmQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E312A180042 for ; Sun, 25 May 2025 21:15:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh-a1-smtp.messagingengine.com (fhigh-a1-smtp.messagingengine.com [103.168.172.152]) (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 ; Sun, 25 May 2025 21:15:48 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id 6922411400BE for ; Sun, 25 May 2025 17:17:55 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-10.internal (MEProxy); Sun, 25 May 2025 17:17:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; 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=fm1; t=1748207875; x=1748294275; bh=YH9MC70I9j/FWqDMDQbbEcuqQZiEQ738UAv8DanutM4=; b= FN+i2Nhj4uY145gGASLEHHPvTaVkOwgg/4nf/TCRgkvG7EYNp9M5hMEYvlCc66+z HL/52JQlYv3iFh/oZS4XKvsLxqiV7hu47+MVgrF8Pzvr2+6ABVC/hzbDI7DsThyp pC01GAxv7oCNYWB5YFF3IPxmW3VqjY/lC0TXpSShawpKaezVhtVEBDx0EGvrG7iq EFDO58v6mXkrLlOBnLHHG7OZdp8Hizx9mZHH8APaEr7keGFHT5NDjlVqloU60K0X 01oR/Aqdbx9+t8aG1bCoRC/n1Z8mh40YeWcNwPTRQczJml2cuOkLOQSpXiFkj4Oo rNJ9O25gY4viq2sJus/jVg== 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=fm1; t=1748207875; x=1748294275; bh=Y H9MC70I9j/FWqDMDQbbEcuqQZiEQ738UAv8DanutM4=; b=ovSkzQlAI2ZeqOEzv qjdkoj0k2BjJdlghsYWcMV2N8ad1KDDnZVMcB1I0UY3C4xD9hZ2IZlyK2HCXU4kC 1UxYMgu2XB1KG+urZ978fAsxoMOPq1kWzfpsd7fIXvx3IVtm5tRBtealR/EgOTqP 5z65jSOY/iBpgKUzhltYi59sS0SR6kyBMsfyCsh/zuKk5G2/xWuyQS8goIFVruTp 2dA5F2YDwm8MtAJk4Th9Ek/qoJ/t/Pe0XqS21TN2eXB5rjhn2nCNUhsxxwtXhOYK 8S68bCjJ/VrO3ZQsTvjUkmREzCBvZqQIQWqzXw2mb7j5uWoqlO8sWqqamsbEVhWy A4+Rg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgdduheeijeculddtuddrgeefvddrtd dtmdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggft fghnshhusghstghrihgsvgdpuffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftd dtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttddvjeenucfhrhhomhep fdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgnfdcuoehimhhsohhprdhphhhpse hrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnhepffekveduffduvdehjedvfeek leeftddugeefheejudehgeeiudffgeeggeevfeehnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdrphhhphesrhifvggtrdgtohdr uhhkpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhope hinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sun, 25 May 2025 17:17:54 -0400 (EDT) Message-ID: <645062ce-bbd2-4756-a863-0cc175972a52@rwec.co.uk> Date: Sun, 25 May 2025 22:17:53 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] Module or Class Visibility, Season 2 Content-Language: en-GB To: internals@lists.php.net References: <9A26F72B-D0EF-414F-B193-BED3CAB26A0B@rwec.co.uk> <9f6a0d6e-27c3-4f77-aed6-e55147442b6f@app.fastmail.com> <673fd2db-b07f-439b-a4f2-e9519108d159@app.fastmail.com> <78641D8B-AF1D-4912-920A-D75A37C32F05@rwec.co.uk> <354cb888-97c4-4f8c-a0da-359d1e63c0f9@rwec.co.uk> <10D95B6E-094B-4EAE-A18A-AF6B795CB352@rwec.co.uk> <2adbff61-5e11-4d39-ab5c-d7950a4550a6@app.fastmail.com> <79E7FA26-2F5A-470C-B1DF-12CC46A08FE5@rwec.co.uk> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 25/05/2025 09:27, Rob Landers wrote: > Here are my thoughts, but first some vocabulary: > - direct dependency: a package that is used by the current package > - exported dependency: a direct dependency that can be used outside > the current package > - peer dependency: an indirect dependency on another package that > isn’t required to function but may offer additional functionality if > installed. I have no idea how this would be defined or used yet. > - package: the physical artefact containing one or more modules. It seems my repeated suggestions of "container" or "sandbox" as the key concept aren't being picked up. I'm still not sure if people disagree with my reasoning, or just don't understand the distinction I'm trying to make. A key point I want to reiterate is that I think 99% of PHP applications should not be using the feature we're talking about here. Most of the time, having a package manager resolve a set of constraints to a set of versions that are all mutually compatible is emphatically a good thing. I also think that the "elephpant in the room" here is that any implementation of this sandboxing is going to be imperfect, because it just doesn't fit with PHP's nature. There are too many cases like `return ['\SomeNs\SomeClass', 'someMethod'];` where the compiler won't know that a class name is being used, so won't know to rewrite/alias/whatever to the sandboxed version. It may actually be that anything we design on this list is doomed to be worse than existing userland implementations, because userland tools can make specific assumptions about things like the WordPress core which we could never build into the engine. > Thinking back on several of my implementation explorations of nested > classes, it should be possible to identify if a dependency/class is > able to be used outside the package during compilation. I think there are many types of "dependency" where you can't automate the decision, e.g. namespace MyPlugin; class MyLogger implements \Psr\Log\LogInterface {     public function logWithBellsOn(\DingDong\BellInterface $bell, string $message): \Duolog\Message {         return new \ExtraLoud\Message(new \Helpful\BellAdapter($bell), $message);     } } Does that refer to a global \Psr\Log\LogInterface, or a sandboxed \MyPlugin\Psr\Log\LogInterface? Is \ExtraLoud\Message a dependency which should be imported/exported, or a hidden implementation detail? And so on, for every class/interface mentioned. Only the code's author can say which was intended in each case. > So, you could imagine a generated package manifest might look > something like this: > > { >   "rootNamespace": "OfficeSuite" >   "dependencies": { >     "AlicesCalendar": "^1.0.0", >     "BobsDocs": "^0.1.0" >   }, >   "exports": { >     "dependencies": ["AlicesCalendar"], >     "functions": ["OfficeSuite\doSomething"], >     "classes": [] >   } > } Just to recap, the example wasn't of an office suite. AlicesCalendar and BobsDocs were supposed to be two unrelated WordPress plugins, which both happened to use Google's SDK. The only application that would know about both of them is WordPress, and it wouldn't need to export anything. The way I'm picturing it is more like this: ``` // The bootstrap file in AlicesCalendar will register a directory of files as a "Container" // Within this Container, class definitions and references are rewritten to use a unique prefix // The Container also has a separate autoloader stack Container\register(     // This prefix is added to all names to make them unique     // e.g. \Monolog\Logger might become \__Container\AlicesCalendar\Monolog\Logger     prefix: 'AlicesCalendar',     // Code in any file in these directories is considered to be "inside" the container     directories: [          '/var/www/wordpress/wp-plugins/AlicesCalendar/src',          // This directory is probably populated by Composer, but the Container logic doesn't care about that          '/var/www/wordpress/wp-plugins/AlicesCalendar/vendor',     ],     // Classes that should be "imported" from outside the Container     // Classes matching these patterns will not be auto-prefixed     // If they are not defined before use, the "host" (e.g. WordPress core) autoload stack will be called     import: [         // Classes inside the Container can implement the shared definition of LoggerInterface         '\Psr\Log\LoggerInterface',         // Classes inside the Container can make use of this namespace of classes defined outside the Container         '\WordPress\PluginTools\*'     ],     // Classes that should be "exported" from inside the Container     // These will use the autoload stack inside the Container, but will not be auto-prefixed     export: [         '\AlicesCalendar\PluginDefinition',         '\AlicesCalendar\Hooks\*'     ], ); // A completely unmodified Composer autoloader is loaded // Because it's inside the Container, everything it registers will be on a separate stack require_once '/var/www/wordpress/wp-plugins/AlicesCalendar/vendor/autoload.php'; // The plugin is registered to the application, which doesn't need to know about the Container setup wp_register_plugin('\AlicesCalendar\PluginDefinition'); // In a completely separate file, BobsDocs does all the same setup // It lists its own imports and exports, and uses its own unique prefix // Any relationship between the two plugins happens in the WordPress Core code as usual ``` The guiding principle is that the code inside the container should need as little modification as possible to be compatible, so that all the code on packagist.org immediately becomes available to whatever plugin wants it. -- Rowan Tommins [IMSoP]