On Tue, May 13, 2025, 18:35 Deleu <deleu...@gmail.com> wrote:

> Hi!
>
> It's been a few days since I wanted to send this email to internals, but
> real life has been a bit chaotic so I apologize if it comes off as if I
> didn't research the archives enough. I glossed over the Module conversation
> from 10 months ago and the one that recently surfaced and after deeply
> thinking about Rowan's and Larry's comments I wanted to throw this idea
> into the pit.
>
> Lets preface the conversation with the fact that 1) a module system for
> PHP has been discussed for several years and 2) if there was an easy and
> perfect solution it would have been long implemented by now.
>
> If we consider how GitHub, Composer and Docker Hub works, we can pin a
> very important aspect of "namespaces": {entity}/{project}.
>


Hi, thank you for starting this thread.

I have a similar thing, an idea that was sitting on my mind that I want to
put in writing, so I will share it here.

First of all, I want to acknowledge the problems with big projects, big
monoliths that can only have one composer.json and many libraries needed,
that would eventually clash and make upgrades harder than they need to be.

Can we develop the modules concept without linking ourselves to namespaces
or any other new entity?

I think it might be possible, if every symbol that is defined is attached
to a module when it is loaded.
And we can use something like:
```
module(string $name, callable $closure);
```

The $closure is defined in the current module, but is executed in the new
module.
Anything else follows the logic: the functions and methods are executed in
the module where they are defined and associated with. Any new symbols
defined inherit the current module.

When a module is defined by another parent module, a relation will be
created between them and the parent module would get access to the child
module symbols, but not also the other way around.

There is no need to change anything on the libraries code but only on
composer and autoloading. That is the key point for easy adoption.
Composer-related, each installed package will be loaded in their own module.

What is yet to figure out:
 - can we define internal modules, where the child module symbols are
visible only in the parent defining module and not any level up?
 - once a module defined, can the parent - child relation be
redefined/changed/removed?


I apologize if this changes the solution discussion, but I didn't wanted to
start a new thread on the same topic.

-- 
Alex

Reply via email to