Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127371 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 497BE1A00BC for ; Thu, 15 May 2025 08:35:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1747298004; bh=mH6iblOE9slIJ9i64xAqHiWMdCGd8TkwiBciZ6J792o=; h=Date:From:To:In-Reply-To:References:Subject:From; b=eh4buxaI5+859vKo/vbs60l/34/AwxIPwilsF2JqhpPL8rCmKKLQmsorpfgNM0ixe lXadEfj39x27oWTXJvfoZzPkEUGZOV7mVzEAfhnC7vYJcWCGeD20zPagIbywl9fFf3 un/NFjNmmrw1V2eHHYoQFj56cgqIv+9tlBNpSMXOxafDK4VpSUsM23MX0Z2z4a0Fb5 aE+mNXbvwqHuGxa4ukSrWS3JrU+kVA1mGS0UkwyNmINvi4/Y3HgQL7CTuypbAhJbqr sssTJJVXgFcbeypF6SweYOfnVbjjWgUhId7d+xXCsciAarlE/xUd9saud54x9Tr1Eg odRFfoEpl7H6w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2B6D51801D8 for ; Thu, 15 May 2025 08:33:23 +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,RCVD_IN_MSPIKE_H2,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-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)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 15 May 2025 08:33:22 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 4F80B11400D6 for ; Thu, 15 May 2025 04:35:33 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-05.internal (MEProxy); Thu, 15 May 2025 04:35:33 -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=1747298133; x=1747384533; bh=xDEduQYoCv uiY+HugO+lVvD9NuN+nWFCbb1CetaTxY4=; b=JnlVK6zwEYz0MjmZ3/pcVFsc2c dvxk+AGK4RKVmSABnK0UA9VB2JqKd46WsQzds9i1ouN7xCJjGv8GStNwE7zU9cSq 7ymLUXZhKcMJBJ41wuCovSN6p/SSKUG6rtyy4zXzUtrS8B6fh5wyC5p4kTKzdys8 nlCxBh5ZcTgRcvq6z44SsR4A7ExIKAUXmR+BGlJkQskdbf92ovUGnifbgVlINZcK XYgvgT0CcS404p124cOSokr6kE8ekH+h4l3r8mzZfPua8HrhVLhi3QIktWdGcsAN 755PlvP43TqRwgypW/btYnj6cnjHYL2Lm+iijSLV6JRi1zVismpcM7Z8bHCg== 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= 1747298133; x=1747384533; bh=xDEduQYoCvuiY+HugO+lVvD9NuN+nWFCbb1 CetaTxY4=; b=IVIiiCyWmigvPwLVP9Rr40v8wlzx3GqeJbYrUp8a1jue5YVeSiC 2ZJxXvBiYvGM7SreyFSiSpd54fzZiHijoGjFBuuKBHzAepMJ4iS5kUE2S8cJBYJ2 h1Qklp1+uLROF9G9VpbGjmXR24wt1J92manQsU5qlRagf7rBavQs6Ne9UsKh81oh wBb6xwTyP0PzL2xQk6KrbJdFsYRltSGYZ6FKvwnAez/qepkdC+6CVuXroTuBvA7s 7Ni7eYRjXyr+Xw2Me1BTjlwHOCym27enRXIpTHM71YcOuVehr0dwPqOYMd1k2eSV en2YGVSY971rRVx1rrYFkUd94f/gVdBY3Zw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeftdelgedtucetufdoteggodetrf 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 DD215302005D; Thu, 15 May 2025 04:35:32 -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 10:35:12 +0200 To: internals@lists.php.net Message-ID: 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=a82d084f415f41f1954d555ea63673d5 From: rob@bottled.codes ("Rob Landers") --a82d084f415f41f1954d555ea63673d5 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 o= ne 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 differe= nt approaches to this. For example, JavaScript allows each module to "cl= ose 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 fea= ture, it *requires* it, as a fundamental design decision:=20 >=20 > - In JavaScript, Python, etc, when you declare a function or class, yo= u 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 list. Code reuse is about kno= wing the global names of things.=20 >=20 > It's worth noting that JavaScript didn't need to add *any* features to= make NPM, Bower, etc work; everything they do is based on the fact tha= t 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 t= he *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 s= olve.=20 >=20 > And that in turn is why I was reaching for Linux containers as an alte= rnative analogy, to think about the problem without jumping to the wrong= solution. >=20 > Rowan Tommins > [IMSoP] >=20 Hey Rowan, When working on nested classes, I did spend quite a bit of time tinkerin= g with alternative implementations. One of those implementations was hav= ing the ability for classes to have their own class tables (both literal= ly and emulated via name mangling) which would have allowed for classes = to have private classes that could share names with external classes. Th= is turned out to be an utter disaster of an idea for many reasons. Namel= y, PHP doesn't really have any native support for shadowing names. Sure,= there is aliasing via use statements, but that only works for classes o= utside the current namespace. As long as we can guarantee that a module = acts as a special namespace (under the hood), the only potential for col= lisions will be in the module itself. All that is to say that I don't think comparing PHP to JavaScript is app= ropriate when considering modules. JavaScript doesn't have types, so I c= an pass you an EpicStringV2 when you're expecting an EpicStringV1, and a= s long as my EpicStringV2 has the right prototypical behavior and data, = it will work just fine. PHP is typed, and fairly strongly typed. There i= s effectively no way to have multiple versions of the same type running = around a codebase and pass type checks. Changing this would be effective= ly impossible and probably unsound from a type-theory perspective. =E2=80=94 Rob --a82d084f415f41f1954d555ea63673d5 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Thu, May = 15, 2025, at 10:11, Rowan Tommins [IMSoP] wrote:


On 14 May= 2025 22:27:32 BST, Rob Landers <rob@bottled.codes> wrote:
>
>As writte= n, that simply isn't possible in PHP because there is only one class all= owed with a given name. Names of classes are global. I don't think this = has to be the case, though. Different languages take different approache= s to this. For example, JavaScript allows each module to "close over" it= s dependencies so each module can import its own version of dependencies= .

I would say that JavaScript doesn't just *all= ow* this, as an added feature, it *requires* it, as a fundamental design= decision: 

- In JavaScript, Python, etc, = when you declare a function or class, you are creating an anonymous obje= ct, and assigning it to a local variable. Code reuse requires you to pas= s that object around.
- In PHP, Java, C#, etc, when you declar= e a function or class, you are adding a permanent named item to a global= list. Code reuse is about knowing the global names of things. 

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

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. 

<= /div>
And that in turn is why I was reaching for Linux containers as= an alternative analogy, to think about the problem without jumping to t= he wrong solution.

Rowan Tommins
[IMS= oP]


Hey Rowan,

When working on nested classes, I did spend quite a= bit of time tinkering with alternative implementations. One of those im= plementations was having the ability for classes to have their own class= tables (both literally and emulated via name mangling) which would have= allowed for classes to have private classes that could share names with= external classes. This turned out to be an utter disaster of an idea fo= r many reasons. Namely, PHP doesn't really have any native support for s= hadowing names. Sure, there is aliasing via use statements, but that onl= y works for classes outside the current namespace. As long as we can gua= rantee that a module acts as a special namespace (under the hood), the o= nly potential for collisions will be in the module itself.
All that is to say that I don't think comparing PHP to JavaS= cript is appropriate when considering modules. JavaScript doesn't have t= ypes, so I can pass you an EpicStringV2 when you're expecting an EpicStr= ingV1, and as long as my EpicStringV2 has the right prototypical behavio= r and data, it will work just fine. PHP is typed, and fairly strongly ty= ped. There is effectively no way to have multiple versions of the same t= ype running around a codebase and pass type checks. Changing this would = be effectively impossible and probably unsound from a type-theory perspe= ctive.

=E2=80=94 Rob
<= /body> --a82d084f415f41f1954d555ea63673d5--