On 14 May 2025 22:27:32 BST, Rob Landers <rob@bottled.codes> 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 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.
I would say that JavaScript doesn't just *allow* 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 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 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 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.
And that in turn is why I was reaching for Linux containers as an alternative
analogy, to think about the problem without jumping to the wrong solution.
Rowan Tommins
[IMSoP]