On 7 May 2025 21:51:29 BST, Michael Morris <tendo...@gmail.com> wrote:
>On Wed, May 7, 2025 at 3:24 PM Rowan Tommins [IMSoP] <imsop....@rwec.co.uk>
>wrote:
>
>Other libraries have the means to import into a namespace because their
>namespaces aren't just a quick and dirty string replacement. I've even
>proposed such a long, long time ago - allowing namespace to be the second
>argument of require, only to have that shot down as "require isn't a
>function." or some such.
I've no idea what you're saying here, sorry. I never mentioned autoloading in
my message, because it's largely irrelevant. What's relevant is how you
identify something that's been declared (e.g. a class).
>> 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.
>
>
>It's not just WordPress.
That is why I said "plugin architectures like WordPress". I am absolutely aware
that it is an example, not something unique.
>I've seen Strauss in action. It's called monkey-typing. Other languages
>support this sort of monkey typing to some degree - PHP can only do it by
>doing an expensive and error prone programmatic keyword search of the
>source files and transforming them. The end result has to be shipped with
>the module, severing its dependencies from getting security updates.
So, you don't like the first example I happened to pick in a 10-second
search... More interestingly:
Firstly, can PHP do something to make the rewriting easier? I've no idea, but
if so, let's talk about it.
Secondly, can the rewriting be done at install time rather than in advance? I
see no reason why not; seems like something to tinker with in a Composer
plugin, off-topic on this list.
>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.
>>
>
>So what do you suggest then? Go's model? Rusts? Gradle or Maven from
>Java? Shooting down stuff is trivial, finding solutions is the real work.
I suggest starting with what we already have: build modules on top of
namespaces, not as something new and orthogonal; and leave package *management*
(version resolution, installation, etc) to userlan, while recognising that
Composer is overwhelmingly the most popular implementation.
That probably means that rewriting namespace prefixes remains the only way to
isolate "private" versions of a dependency, and I am totally fine with that.
Rowan Tommins
[IMSoP]