On Thu, Mar 6, 2025, at 22:00, Tim Düsterhus wrote:
> Hi
> 
> On 3/6/25 20:08, Niels Dossche wrote:
> > What I'm less in favor of is the implementation choice to expose the inner 
> > class as a property/const and using a fetch mode to grab it.
> > That feels quite weird to me honestly. How did you arrive at this choice?
> 
> Somewhat relatedly, the RFC does not mention how the choice of `::` as 
> the separator interacts with the following features (i.e. what will the 
> result of each of the statements be):

Sorry to double post, but before updating the RFC, I figure I'll go ahead and 
answer here and see if it is what you expect.

> 
>      Closure::fromCallable('Outer::Inner::method');

You end up with:

object(Closure)#1 (1) {
  ["function"]=>
  string(20) "Outer::Inner::method"
}

>      new ReflectionMethod('Outer::Inner::method');

The current implementation returns an error here, but it should give you an 
actual ReflectionMethod. I'll have to take a look and see what is going on.

>      defined('Outer::Inner');

This returns: `true`.

>      constant('Outer::Inner');

This returns:

string(12) "Outer::Inner"

>      $inner = 'Inner';
>      Outer::{$inner};

This does nothing (but resolves to "Outer::Inner")

> … and any other meta-programming functionality working on class 
> constants or static methods.
> 
> Also, what will happen for:
> 
>      class P {
>          class Inner { }
>      }
> 
>      class C extends P {
>           const Inner = 'x';
>      }
> 
> (and vice versa)

This is a really good one. If for no other reason than I did a really poor job 
of explaining resolution(?) in the RFC. `P::Inner` belongs to `P`, not to `C`, 
so you can do `new C::Inner()` and it will resolve to `P::Inner()`:

object(P::Inner)#2 (0) {
}

As with other static things in PHP, you can do some really strange things like 
this. This is similar to how you can redefine static constants in subclasses.

My main goal is to prevent exactly this type of confusion:

new C::Inner() 
vs. 
echo C::Inner.

> Somewhat relatedly, the RFC does not mention how the choice of `::` as 
> the separator

This felt the most natural to me, but as with all syntax on this list, I'd be 
interested in other colors to paint the bikeshed! Especially ones that I may 
not have previously considered!

— Rob

Reply via email to