On 10 July 2026 13:46:08 BST, Holly Schilling <[email protected]> 
wrote:
>
>Now knowing that, it makes the case for using a different keyword like 
>`extension` much stronger since that is not the case for an extension. 
>Everything on an extension is type-checked at compile time, save some edge 
>cases with scalars. 

I'm not sure if I'm misunderstanding, but if you're saying that every reference 
to $this in the body of an extension method will be analysed by the compiler 
against the class definition, that would be extremely surprising to PHP users. 

As far as I know, *all* method and property despatch in PHP is dynamic, whether 
it's on $this or any other object reference. In other words, only when you 
actually *run* code like $this->whatever() does PHP even try to look for the 
method definition.

Trying to validate that at compile time would presumably break any dynamic code 
- $this->whatever() would not be allowed to fall back to __call('whatever'), 
and $this->{$someVar}() would have to refuse to compile.

While we could argue whether those features make PHP better or worse, having 
them forbidden just in the context of extension methods would feel very 
arbitrary.

However, perhaps we're talking at cross purposes, and this is not actually what 
you're proposing.

Regards,

Rowan Tommins
[IMSoP]

Reply via email to