Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127540 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 0361E1A00BC for ; Mon, 2 Jun 2025 20:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1748895990; bh=LWMkU72qAeWz9v+CGM2hTbOV2CcX6b0c4k9Nq/T6hDA=; h=Date:Subject:To:References:From:In-Reply-To:From; b=F8PMwxiGUjnDbRzqbqpQ3vYX8+/POLPfVuGnf1U5GOqWuOL/bLBRwU5KM0/6aNZwl oy1+wp+g/4XOWKVQzTCQ7PQvZFU2pJ4iIiv+VBVKDiP0q9eN6h9SsCIOHC/c/1zlYJ Xczkx/Eu4KDGK5DlP4o6mjA7yw/d0Y/oVXfrtm2ncD+boNTflwGfxPAgKD5rpptMwV DI8PJIABjYssbSeaDj7myWdh5IZ70nbFDvA7Pce+83y4LJKjiVeRv4kubP1dlsSuY5 D9kftVFWL2/yhGONgXBGI+6qzWcjX5WgF4IJn967C9OQ93towWFQV6eCJ1FRiCMDV8 2wBx9abTa6JcA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2A1A9180083 for ; Mon, 2 Jun 2025 20:26:29 +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=-3.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,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-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) (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 ; Mon, 2 Jun 2025 20:26:28 +0000 (UTC) Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id CBA09114014F for ; Mon, 2 Jun 2025 16:28:32 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Mon, 02 Jun 2025 16:28:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :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=1748896112; x=1748982512; bh=GTSG6amyaZ jIJ2HO4VXKjFTMzzsd5utlYsSXgBQr4og=; b=TudgELpBMdMQcYUB3yggzyDu3D fAJiZVyVQ2GdiibhEFDOcH+Aov4dIb8tInkvoTEUJVM5PbDcd4hRsN6ogzqBTMHS Oub5Mp80hE9Tsh8Q8hgf4bY382D+urDk6MxeNmNnfB5dw9L8ZXY9C5Mp/a5vGVnU cVPtAJly28H9fJ+F8RKvQQMNVyS8HDU/hY9fUZnTKvWSfy/jtuLkt9H79Yp0X+nA p2UmwekGEgYq7b7ABcknEZYofXqhwSOrP4pD5M+PyD6BS2/yC3fd19mKGZfd7pBd tBpomP5qD7n4NC1SlVU7AjQQRu3PYuF6xceMt0mbGI1/bEhGX/xBAlUbvwPA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= 1748896112; x=1748982512; bh=GTSG6amyaZjIJ2HO4VXKjFTMzzsd5utlYsS XgBQr4og=; b=WKn5Uyswa3UjmuYO/oNa2usoM4/I2PCFJwXQKA3NTW5CuthX6KR +PrdfR7Fwa2MCoAt4tSsR1BbK25ZVDxW2cxniTZCcQIaZ89Hii+e7+e0U+TRai2n WvD9oFCamegbrO3bNm9Hn/wKb6JDnATVxoQNV+4O0qgXDylPfx42LMBNgYzR9BfJ EF+THamPkchSHxBcCP/Cv5pBof5zTjKp0sJzkiAnfFFyLyt6QrzDmLBXxkPAaBS0 zeDiHeIlGvPAGFksw2UTrFPb91vwWWc/poiZvkg/Fjy7avez221ZWHmJqeNtpgTI 9+0FYJmq4WJhMyzaKeWNArIUWXTgp28N/JA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgdefkeeifeculddtuddrgeefvddrtd dtmdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggft fghnshhusghstghrihgsvgdpuffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftd dtnecunecujfgurheptgfkffggfgfuvfhfhfgjsegrtderredtvdejnecuhfhrohhmpedf tfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrh ifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpeehteelieeigfeuudeiueeiffdv veehudeufeekjeeugffffedtiedtgeettdelteenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhu khdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepih hnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 2 Jun 2025 16:28:31 -0400 (EDT) Content-Type: multipart/alternative; boundary="------------fMGZ2pr9uoiJjpVmOsRxuD9U" Message-ID: <57d08124-fb6a-4e0b-8d42-bdb645571b13@rwec.co.uk> Date: Mon, 2 Jun 2025 21:28:30 +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: <10D95B6E-094B-4EAE-A18A-AF6B795CB352@rwec.co.uk> <2adbff61-5e11-4d39-ab5c-d7950a4550a6@app.fastmail.com> <79E7FA26-2F5A-470C-B1DF-12CC46A08FE5@rwec.co.uk> <1c6dcd84-9016-48e1-971f-de7749cbdce8@rwec.co.uk> <44F59416-3922-4AF4-881A-C64F2C4E9345@rwec.co.uk> <7F11844A-A98C-4843-BC94-815FBCD2B73F@garsi.de> <7840468C-F60C-4A44-AE40-16F9007EF428@rwec.co.uk> <160E9B1D-9AF6-479B-A628-A73C618D7C1B@garsi.de> <2c5c241c-bd05-4200-b6ee-e94c8ab0db1b@rwec.co.uk> <894DC5D3-3CDD-479F-BAC1-70EE1AE0C5E2@rwec.co.uk> <5eb5b1b4-7cb2-4a2b-afdd-ad3e83ae856d@app.fastmail.com> In-Reply-To: <5eb5b1b4-7cb2-4a2b-afdd-ad3e83ae856d@app.fastmail.com> From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") This is a multi-part message in MIME format. --------------fMGZ2pr9uoiJjpVmOsRxuD9U Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 02/06/2025 17:57, Larry Garfield wrote: > Well, now you're talking about something with a totally separate compile step, which is not what Michael seemed to be describing at all. But it seems like that would be necessary. There's definitely some crossed wires somewhere. I deliberately left the mechanics vague in that last message, and certainly didn't mention any specific compiler steps. I'm a bit lost which part you think is "not what Michael seemed to be describing". Picking completely at random, a file in Monolog has these lines in: namespace Monolog\Handler; ... use Monolog\Utils; ... class StreamHandler extends AbstractProcessingHandler { ... $this->url = Utils::canonicalizePath($stream); My understanding is that our goal is to allow two slightly different copies of that file to be included at the same time. As far as I know, there have been two descriptions of how that would work: a) Before or during compilation, every reference is automatically prefixed, so that the class is declared as "\__SomeMagicPrefix\Monolog\Handler\StreamHandler", and the reference to "\Monolog\Utils" is replaced by a reference to "\__SomeMagicPrefix\Monolog\Utils". There are existing userland implementations that take this approach. b) While the class is being compiled, PHP swaps out the entire symbol table, so that the class is still called "\Monolog\Handler\StreamHandler", and the reference to "\Monolog\Utils" is to the class of that name in the current symbol table. In a different symbol table, both names refer to separately compiled classes. The "new namespace root" in my last message is either (a) the special prefix, or (b) the actual root of the new symbol table. In either case, you need to decide which classes to declare under that root; either recursively tracking what requires what, or just where on disk the file was loaded from. Even if we're willing to require the authors of Monolog to rewrite their library for the convenience of WordPress plugin authors, I don't see how we can get away from every class in PHP being fundamentally identified by name, and the compiler needing to manage those names somehow. We can imagine a parallel universe where PHP declarations worked like JS or Python: import * from Monolog\Handler; ... $Utils = import Monolog\Utils; ... $StreamHandler = class extends $AbstractProcessingHandler { ... $this->url = $Utils::canonicalizePath($stream); But at that point, we're just inventing a new programming language. > At which point, we're basically talking about "load this Phar file into a custom internalized namespace", which, from my limited knowledge of Phar, seems like the most logical way to do it. That also sidesteps all the loading and linking shenanigans. I don't think Phar files would particularly help. As far as I know, they're just a file system wrapper; you still have to include/require the individual files inside the archive, and they're still compiled in exactly the same way. Whether we want to isolate "any definition you find in the directory /var/www/wordpress/wp-plugins/foo/" or "any definition you find in the Phar archive phar:///var/www/wordpress/wp-plugins/foo.phar", the tricky part is how to do the actual isolating. -- Rowan Tommins [IMSoP] --------------fMGZ2pr9uoiJjpVmOsRxuD9U Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 02/06/2025 17:57, Larry Garfield wrote:
Well, now you're talking about something with a totally separate compile step, which is not what Michael seemed to be describing at all.  But it seems like that would be necessary.  


There's definitely some crossed wires somewhere. I deliberately left the mechanics vague in that last message, and certainly didn't mention any specific compiler steps. I'm a bit lost which part you think is "not what Michael seemed to be describing".


Picking completely at random, a file in Monolog has these lines in:

namespace Monolog\Handler;
...
use Monolog\Utils;
...
class StreamHandler extends AbstractProcessingHandler {
...
$this->url = Utils::canonicalizePath($stream);


My understanding is that our goal is to allow two slightly different copies of that file to be included at the same time. As far as I know, there have been two descriptions of how that would work:

a) Before or during compilation, every reference is automatically prefixed, so that the class is declared as "\__SomeMagicPrefix\Monolog\Handler\StreamHandler", and the reference to "\Monolog\Utils" is replaced by a reference to "\__SomeMagicPrefix\Monolog\Utils". There are existing userland implementations that take this approach.

b) While the class is being compiled, PHP swaps out the entire symbol table, so that the class is still called "\Monolog\Handler\StreamHandler", and the reference to "\Monolog\Utils" is to the class of that name in the current symbol table. In a different symbol table, both names refer to separately compiled classes.

The "new namespace root" in my last message is either (a) the special prefix, or (b) the actual root of the new symbol table. In either case, you need to decide which classes to declare under that root; either recursively tracking what requires what, or just where on disk the file was loaded from.


Even if we're willing to require the authors of Monolog to rewrite their library for the convenience of WordPress plugin authors, I don't see how we can get away from every class in PHP being fundamentally identified by name, and the compiler needing to manage those names somehow.

We can imagine a parallel universe where PHP declarations worked like JS or Python:

import * from Monolog\Handler;
...
$Utils = import Monolog\Utils;
...
$StreamHandler = class extends $AbstractProcessingHandler {
...
$this->url = $Utils::canonicalizePath($stream);

But at that point, we're just inventing a new programming language.


At which point, we're basically talking about "load this Phar file into a custom internalized namespace", which, from my limited knowledge of Phar, seems like the most logical way to do it.  That also sidesteps all the loading and linking shenanigans.


I don't think Phar files would particularly help. As far as I know, they're just a file system wrapper; you still have to include/require the individual files inside the archive, and they're still compiled in exactly the same way.

Whether we want to isolate "any definition you find in the directory /var/www/wordpress/wp-plugins/foo/" or "any definition you find in the Phar archive phar:///var/www/wordpress/wp-plugins/foo.phar", the tricky part is how to do the actual isolating.


-- 
Rowan Tommins
[IMSoP]
--------------fMGZ2pr9uoiJjpVmOsRxuD9U--