Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127308 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 BE0831A00BC for ; Wed, 7 May 2025 19:24:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1746645735; bh=dG4OBfRP+aRT5AhA0Z8mw85E/c7c8lswTb9ULmAjnio=; h=Date:Subject:To:References:From:In-Reply-To:From; b=kRln/mms4b/52Y06pTTv1zazehEUqdskZThES5glX6l1PBia/KUwS9driEYQJB0OQ bC9LH/vKic9FGjow16tP5uBCl150S1yv7zgsemBBEafD6+Lowgest10RKiDv4SdJe/ s3litoKWU1z4fJbeuHZMx1vyGVdAVEJYTjctrcQgta9/5Xb1oLlfnf6LVvxiTica8y KQDzV56YDThjNnOXQujM6mvr8LqMCFZyrrTG9Pc8Bk+pCBBkxTZjzS88JtzwPF4Ame mg/G/of8rQ1/yuXkZ5qyo55Z/KdoieaujQijMEYgUu6H/l2FzmUIfG4Gd1yNLZpIhC s5f64+qtKv95g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 799D5180084 for ; Wed, 7 May 2025 19:22:14 +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.9 required=5.0 tests=BAYES_40,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.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh-b3-smtp.messagingengine.com (fhigh-b3-smtp.messagingengine.com [202.12.124.154]) (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 ; Wed, 7 May 2025 19:22:14 +0000 (UTC) Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.stl.internal (Postfix) with ESMTP id 4F5CF25400C0 for ; Wed, 7 May 2025 15:24:27 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Wed, 07 May 2025 15:24:27 -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=fm3; t=1746645867; x=1746732267; bh=tRj24s4+Hjv2MZHj0rl/afKIMwU4C3638p7+6+LCv2A=; b= it9Fg++1LG8k70IzPyHHJrvSJkj123GqnmZrYB9dDb8IeRlNwfNCm1qH/5FjONCF u3+fgtxtLW/BVuggtmvD3jymhyvucPmWlqmcrYHI/19kc36Puq0FD6nAFT85T7La wuqixEA3ZnVQT6FWwAxcdxQ5UZ+8uEB8pJ/3ILyYBI4YsYYZRybWt2iUGi3lNhO5 pFdtC9xOWMPmxyPSmYJMovtSC9usqKYWR+KUGWKiCXWknKV6+3TN6BpHSJRcbc1Y wj9Eua92isR9M7g6jXotjm3RHLbN41N+ohEf/HWUnskNnskyMSlFOX9+mE++9DxV v7H5a2CS4GQIsYRCk1KsFg== 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=fm3; t=1746645867; x=1746732267; bh=t Rj24s4+Hjv2MZHj0rl/afKIMwU4C3638p7+6+LCv2A=; b=M5KRtx0Mye5ZMPqdf P4Fe5BKo2/UHl1gN4N4gfQP16E5cN5BBWPB2Elovtpzz+Zlyqml5THL1O7e+U7Cl bIw8WJj/E52JCpFexmqa8W1rZu686j9SRd+ZjWcMyrQ1NVDb584jZ6tpIaC2LseV SYxwnycrKu2H4XULxq8WPekNyLMJ7wD/OSVlAsbzxCtyIUgSwmGUgktx/Pkydj79 ndqyOnOvDcRU4zckVGOx94r5S/3pX09GxjLCf7dHeg2C2ATRqRcAaRYyogLYFHJ+ iYD7VlXFkqGs5BUL3hKojgwwC/VfJEseLF8lz2/TvD8ZaLdX6HMg2rKNBX3SpFfR ZNMbA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvkeejieelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefkff ggfgfuvfhfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpedftfhofigrnhcuvfhomhhm ihhnshculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqe enucggtffrrghtthgvrhhnpeelfeeugfeghffhjeeivddtuefgveevgffgueefheeitdeg heeukefgjefffeffveenucffohhmrghinhepghhithhhuhgsrdgtohhmnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdrphhhphes rhifvggtrdgtohdruhhkpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuth dprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 7 May 2025 15:24:26 -0400 (EDT) Message-ID: <6d2adbbb-f4fa-41e6-9ec1-179685ded039@rwec.co.uk> Date: Wed, 7 May 2025 20:24:24 +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] Modules, again. To: internals@lists.php.net References: Content-Language: en-GB 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 04/05/2025 08:34, Michael Morris wrote: > PHP has no way of dealing with userland code trying to write to the > same entry > on the symbol tables.  Namespaces are a workaround of this and > combined with > autoloaders they've yielded the package environments we currently have > (usually > composer), but at the end of the day if two code blocks want different > versions > of the same package invoked at the same time there's going to be a > crash. This > is seen most visibly in WordPress plugins that use composer, as they > resort to > monkey-typing the composer packages they consume to avoid such collisions. I think there are two different problems being muddled here: 1) How can two *completely unrelated* libraries avoid *accidentally* declaring something with the same name? 2) How can two versions of *the same* library be used in different parts of the same running program, despite overlapping names? Namespaces are not a workaround to problem number 2, they are a solution to problem number 1: every library chooses a prefix, and avoids declaring symbols with prefixes used by other libraries. Problem number 2 is what you seem to be trying to address. In languages like EcmaScript/JavaScript/TypeScript, the solution (to both problems) is to say that declarations don't have a canonical name. They're values that you can pass around, and their name is whatever a local scope says it is. This has major implications on both the language and its ecosystem: - contracts between libraries need to be structural, because there is no name that all libraries agree on for an interface/protocol/whatever - package managers don't resolve the graph of dependencies to a consistent set, they install multiple copies of the same library, for use in different scopes - package authors are free to depend on mutually incompatible concrete implementations, rather than agreed or de facto standards and interfaces NPM is notorious for creating a giant directory of tiny modules, because that's what the language design encourages. That's not how PHP works, and it never will be. In PHP (and other languages like Java, and C#), declarations have a single fully-qualified name. If you want two different versions of the same library, you will need to find a way to make their declarations use different fully-qualified names. Most applications do not have this problem. In fact, I would say that most applications would actively suffer from having multiple copies of the same library installed. The main exception, as you have pointed out, is plugin architectures like WordPress, where the plugin might want to "privately" use some library without impacting the host application and other plugins. For those, userland solutions already exist - a random search turned up this one, which lists some alternatives: https://github.com/BrianHenryIE/strauss?tab=readme-ov-file#alternatives I *do* think PHP would benefit from some native concept of "module" for other reasons, e.g. marking internal components, optimising across multiple files. I *do not* think that ES/JS/TS is a suitable model to look at, because it is starting from a fundamentally different concept of what a declaration is. I also *do not* think that allowing multiple versions of the same library should be a core requirement of any native module support; enabling userland to achieve it efficiently would be a nice to have. -- Rowan Tommins [IMSoP]