On Jul 3, 2024, at 17:16, Michael Morris <tendo...@gmail.com> wrote:
> Can PHP support multiple packages without rewriting the whole engine?  I 
> think so, but it isn't trivial, and the side effects need to be cordoned off 
> so that those who need this complexity can have it while the beginning and 
> intermediate coders can ignore it just like they ignore strict comparison 
> operators and strict typing unless a library they are trying to use foists it 
> on them.

I think that focusing on the syntax and tooling for executing these imports is 
starting at the wrong end of this problem. The bulk of the work for this 
feature is going to be whatever engine changes are required to support 
versioning, not the tooling around it.

To that end - consider the following. Let's say that two different files in 
your project import different versions of package Foo. Foo contains a 
definition of the FooBar class, and contains functions which return that object.

1) If $foobar is one of those FooBar objects, what does $foobar::class return? 
Is it the same as the fully qualified name of FooBar (e.g. "Foo\FooBar")? Does 
the result differ depending on what file contains that code?

2) What happens if you try to pass that string back to something like new 
$class() or construct a ReflectionClass for it? Does that depend on the 
location of the call? What if the call is through something like 
PDO::FETCH_CLASS which occurs within the runtime?

3) Within Foo, would it be true that if $x = new FooBar(), then $x::class === 
FooBar::class? Does this differ outside Foo (with an appropriately qualified 
name for FooBar)?

4) If those two files both create FooBar objects of their respective versions, 
what happens if you try to pass one of those objects to a function in the file 
using the "wrong" version of Foo? Does it pass type checks, and what happens if 
it does? If not, how does the check fail?

5) What shows up in the output of functions like get_declared_classes()? Are 
there multiple instances of FooBar in there for each version? How are they 
distinguished from one another?

Reply via email to