Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127373 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 584F51A00BC for ; Thu, 15 May 2025 09:41:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1747301977; bh=JpVLTuj131CX45DoXtwxxK/UbQTcpOkntNnMoyXYmE4=; h=Date:From:To:In-Reply-To:References:Subject:From; b=Az4aMbah+9ZhZoccPSnQFwSWPzLPmW9JPVyb97rYG8LKPGOv0lfwd/nHIY+mk33Xj Pb/xbDtDfoca9COnoEQGxRZiMjnVpi4/XCWkHJuWQwnbnVniUpspz0NZCy7v4BwyMZ 6RHcoOzXJP2U8IKhfYYeyn04oeO0tYHK1WJvsG/EvBDeDvW+GY4C4qwASOTq8o1Dlg fHwGIaUvsRGwot0bNtwXYmsOle0Hf9Ve8rIXb6gyzm2PxAiAmX1tjW4D74Y3Fjbmlc JL7Quy1r09yDwBan+vbPgy7YRcAm3wp2hyK7rvLYP85vg/wGyP7dxQvxyvE8NLFP73 cM24uqgsoLDRQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1CBA4180051 for ; Thu, 15 May 2025 09:39:36 +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=-2.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,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 fout-a3-smtp.messagingengine.com (fout-a3-smtp.messagingengine.com [103.168.172.146]) (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 ; Thu, 15 May 2025 09:39:35 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id E6063138013C for ; Thu, 15 May 2025 05:41:45 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-05.internal (MEProxy); Thu, 15 May 2025 05:41:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; 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=1747302105; x=1747388505; bh=r/eXNMjeBP cwaXqDgJNPZQZSyjsXTLp36UkxbshFyTs=; b=Y2WG+xFc28QBBx8UEpuN0lSdUH uY77jHD6pA29KeAsjOuXoRdqgHI50Ohz5WpuAwkM+UxQWooz9pJi5hlCm9uZq7Eg IEXjcP0jZnOTI2w2sKgXnEcOkUJ2YQtEQ0GYGbIBJVyN4GTp69EeneuGFtDgcZBj fba5u66lE7S2fq34rjWbDo+EvTSEUfTkmE2kgxDEEKFVZQx58Ff3GvIj7SpuDApA BaFlmAvMMcIpnLXqwu3cc+aibS2RZ9x6yUQZ0VrNRPs3xm+dGlwh12bcotqGauQd 8555tMdnD7ZoDLWD+D+UJP2TUS60qsgkbuKGPVRXKawOLZwczOQDGvuMfPBw== 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=fm3; t= 1747302105; x=1747388505; bh=r/eXNMjeBPcwaXqDgJNPZQZSyjsXTLp36Uk xbshFyTs=; b=rGe4VT7QHwFSj/YF//cb1JQ9TteOegJQTu/I6E52sMeShwNEh56 tpaEJ4tK4QylIf1V9jmXUCOpYWf4XKj9YjbygBrvMTvZMmJ3ig1pQ0UgUVW8iY2Q 3Hiuw409ZVwY0MSaWFkQGl31v2W/U/Epo8fWa4QMai3yb75wqcEksaS991DF4iKe 5932W3GhUbImSFCZRCkDIkN0V5Dk6DOueKNVfJXoDrtfsYGMzRjtb/2oRSSbor2u OUMmuxgI7QQvMzoWATWzbqKOT7oHtiwIYM2V1hZOtBc+uOONjsK1Bp6lJrZOmZxY vra6xRBciQkslqzOEG+pCvvxUO1HVCZGE7w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeftdelheefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefogg ffhffvkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhs fdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtthgvrhhnpedtue ejtdethfeulefhtdelieduteelffdtudelheffgedtieehhfelieejgfevgeenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtth hlvggurdgtohguvghspdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 8309B302005E; Thu, 15 May 2025 05:41:45 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: T018bd9ffc60205f7 Date: Thu, 15 May 2025 11:41:21 +0200 To: internals@lists.php.net Message-ID: <673fd2db-b07f-439b-a4f2-e9519108d159@app.fastmail.com> In-Reply-To: References: <3ae9a6ea-f135-472b-b2bf-e6cd6ebad299@app.fastmail.com> <9A26F72B-D0EF-414F-B193-BED3CAB26A0B@rwec.co.uk> <9f6a0d6e-27c3-4f77-aed6-e55147442b6f@app.fastmail.com> Subject: Re: [PHP-DEV] Module or Class Visibility, Season 2 Content-Type: multipart/alternative; boundary=f480a7e256ea48bdbe9a1f842a8200cd From: rob@bottled.codes ("Rob Landers") --f480a7e256ea48bdbe9a1f842a8200cd Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, May 15, 2025, at 10:35, Rob Landers wrote: > On Thu, May 15, 2025, at 10:11, Rowan Tommins [IMSoP] wrote: >>=20 >>=20 >> On 14 May 2025 22:27:32 BST, Rob Landers wrote: >> > >> >As written, that simply isn't possible in PHP because there is only = one class allowed with a given name. Names of classes are global. I don'= t think this has to be the case, though. Different languages take differ= ent approaches to this. For example, JavaScript allows each module to "c= lose over" its dependencies so each module can import its own version of= dependencies. >>=20 >> I would say that JavaScript doesn't just *allow* this, as an added fe= ature, it *requires* it, as a fundamental design decision:=20 >>=20 >> - In JavaScript, Python, etc, when you declare a function or class, y= ou are creating an anonymous object, and assigning it to a local variabl= e. Code reuse requires you to pass that object around. >> - In PHP, Java, C#, etc, when you declare a function or class, you ar= e adding a permanent named item to a global list. Code reuse is about kn= owing the global names of things.=20 >>=20 >> It's worth noting that JavaScript didn't need to add *any* features t= o make NPM, Bower, etc work; everything they do is based on the fact th= at declarations are objects which can be passed around at will.=20 >>=20 >> That's why I don't think "JavaScript can do it" is relevant, because = the *way* JavaScript does it is impossible in PHP. We're much better off= looking at how *PHP* works, and what problems we're actually trying to = solve.=20 >>=20 >> And that in turn is why I was reaching for Linux containers as an alt= ernative analogy, to think about the problem without jumping to the wron= g solution. >>=20 >> Rowan Tommins >> [IMSoP] >>=20 >=20 > Hey Rowan, >=20 > When working on nested classes, I did spend quite a bit of time tinker= ing with alternative implementations. One of those implementations was h= aving the ability for classes to have their own class tables (both liter= ally and emulated via name mangling) which would have allowed for classe= s to have private classes that could share names with external classes. = This turned out to be an utter disaster of an idea for many reasons. Nam= ely, PHP doesn't really have any native support for shadowing names. Sur= e, there is aliasing via use statements, but that only works for classes= outside the current namespace. As long as we can guarantee that a modul= e acts as a special namespace (under the hood), the only potential for c= ollisions will be in the module itself. >=20 > All that is to say that I don't think comparing PHP to JavaScript is a= ppropriate when considering modules. JavaScript doesn't have types, so I= can pass you an EpicStringV2 when you're expecting an EpicStringV1, and= as long as my EpicStringV2 has the right prototypical behavior and data= , it will work just fine. PHP is typed, and fairly strongly typed. There= is effectively no way to have multiple versions of the same type runnin= g around a codebase and pass type checks. Changing this would be effecti= vely impossible and probably unsound from a type-theory perspective. >=20 > =E2=80=94 Rob Haha, I just reread your email and realized we're basically saying the s= ame thing (I think?). =E2=80=94 Rob --f480a7e256ea48bdbe9a1f842a8200cd Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Thu, May 15, 2025, at 10:35, Rob Landers wrote:
On Thu, May 15, 20= 25, at 10:11, Rowan Tommins [IMSoP] wrote:


On 14 May 2= 025 22:27:32 BST, Rob Landers <r= ob@bottled.codes> wrote:
>
>As written,= that simply isn't possible in PHP because there is only one class allow= ed with a given name. Names of classes are global. I don't think this ha= s to be the case, though. Different languages take different approaches = to this. For example, JavaScript allows each module to "close over" its = dependencies so each module can import its own version of dependencies.<= /div>

I would say that JavaScript doesn't just *allow= * this, as an added feature, it *requires* it, as a fundamental design d= ecision: 

- In JavaScript, Python, etc, wh= en you declare a function or class, you are creating an anonymous object= , and assigning it to a local variable. Code reuse requires you to pass = that object around.
- In PHP, Java, C#, etc, when you declare = a function or class, you are adding a permanent named item to a global l= ist. Code reuse is about knowing the global names of things. 
=

It's worth noting that JavaScript didn't need to add= *any* features to make NPM,  Bower, etc work; everything they do i= s based on the fact that declarations are objects which can be passed ar= ound at will. 

That's why I don't think "J= avaScript can do it" is relevant, because the *way* JavaScript does it i= s impossible in PHP. We're much better off looking at how *PHP* works, a= nd what problems we're actually trying to solve. 

And that in turn is why I was reaching for Linux containers as a= n alternative analogy, to think about the problem without jumping to the= wrong solution.

Rowan Tommins
[IMSoP= ]


Hey Rowan,
<= div>
When working on nested classes, I did spend quite a b= it of time tinkering with alternative implementations. One of those impl= ementations was having the ability for classes to have their own class t= ables (both literally and emulated via name mangling) which would have a= llowed for classes to have private classes that could share names with e= xternal classes. This turned out to be an utter disaster of an idea for = many reasons. Namely, PHP doesn't really have any native support for sha= dowing names. Sure, there is aliasing via use statements, but that only = works for classes outside the current namespace. As long as we can guara= ntee that a module acts as a special namespace (under the hood), the onl= y potential for collisions will be in the module itself.

<= /div>
All that is to say that I don't think comparing PHP to JavaScr= ipt is appropriate when considering modules. JavaScript doesn't have typ= es, so I can pass you an EpicStringV2 when you're expecting an EpicStrin= gV1, and as long as my EpicStringV2 has the right prototypical behavior = and data, it will work just fine. PHP is typed, and fairly strongly type= d. There is effectively no way to have multiple versions of the same typ= e running around a codebase and pass type checks. Changing this would be= effectively impossible and probably unsound from a type-theory perspect= ive.

=E2=80=94 Rob
=

Haha, I just reread your email and real= ized we're basically saying the same thing (I think?).

=E2=80=94 Rob
--f480a7e256ea48bdbe9a1f842a8200cd--