Re: Re: [Concept] Extension methods
| From: | Larry Garfield | Date: | Thu, 11 Aug 2022 14:22:15 +0000 |
| Subject: | Re: Re: [Concept] Extension methods | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118412@lists.php.net to get a copy of this message | ||
On Thu, Aug 11, 2022, at 3:05 AM, Rowan Tommins wrote:
> On 11/08/2022 01:10, Larry Garfield wrote:
>> Would it be OK if extension methods came*before* normal methods?
>
>
> It would certainly be possible, and seems more logical than allowing
> extensions to over-ride __call but not anything else. It does lead to a
> very different feature, though: it means that you can take a fully
> working unit of code, add a "use extension" line at the top, and change
> the behaviour of that code.
>
> I haven't looked in detail at how other languages implement them, but my
> impression is that such a behaviour change would be something other than
> an "extension method" as normally understood.
>
>
>> Would that allow a compile time translation of this:
>>
>> use extension Foo:bar;
>>
>> $collection->bar($b);
>>
>> to this:
>>
>> Foo::bar($collection, $b);
>
>
> Unfortunately not, because the compiler doesn't know anything about the
> type of $collection, so doesn't know whether to apply the extension. The
> process would look something like this:
Ah, good point. I keep forgetting that even though well-written code has pretty sold type
information, it's not quite enough to be able to do anything useful at compile time, generally.
Poopy. If that makes the performance even worse on every method call then it's definitely not
worth considering.
--Larry Garfield