On 10 July 2026 15:44:47 BST, Holly Schilling <[email protected]> 
wrote:
>
>Dispatched inside an extension method is exactly the same as anywhere else 
>besides that `$this` only has the public surface accessible. If a user calls a 
>method name that doesn’t exist, it does the same as usual. That hasn’t changed.

Gotcha. The confusion came from the mention of "compile-time", which isn't when 
visibility checks happen. The method is looked up, then its visibility flags 
are enforced, all at runtime.

So another way of putting it is that an extension method has no privileged 
access to the target class.

That is indeed different from a trait. Whereas a trait is pasted into the 
class, an extension function stays separate and $this is just a normal object 
reference being accessed "publicly".

Regards,

Rowan Tommins
[IMSoP]

Reply via email to