[PHP-DEV] Re: [Concept] Extension methods

2022-08-10 Thread Paul Crovella
On 8/10/2022 7:17 AM, Alex Wells wrote: This solution works, but in practice is rarely used. The reasons are: - there's no IDE completion: `$collection-> ` <- here I want IDE to auto-complete the `map` method somehow, but since it's a function this is impossible This isn't impossible. There's n

Re: [PHP-DEV] Re: [Concept] Extension methods

2022-08-10 Thread Larry Garfield
On Wed, Aug 10, 2022, at 5:23 PM, Deleu wrote: > On Wed, Aug 10, 2022, 11:30 PM Rowan Tommins > wrote: > >> >> To be honest, I put them in that order more for "purity" reasons: if they >> come before __call, they can change the existing behaviour of the class, by >> defining an extension method wi

Re: [PHP-DEV] Re: [Concept] Extension methods

2022-08-10 Thread Deleu
On Wed, Aug 10, 2022, 11:30 PM Rowan Tommins wrote: > > To be honest, I put them in that order more for "purity" reasons: if they > come before __call, they can change the existing behaviour of the class, by > defining an extension method with the same name as a "virtual" method > implemented wit

Re: [PHP-DEV] [Concept] Extension methods

2022-08-10 Thread Alex Wells
> On 11 Aug 2022, at 00:30, Rowan Tommins wrote: > > a class implementing __call is assumed to reserve *all* method names. This does make sense. Either an extension has precedence over class methods or it does not; having extension methods in the middle of statically defined methods and __cal

Re: [PHP-DEV] Re: [Concept] Extension methods

2022-08-10 Thread Rowan Tommins
On 10 August 2022 18:52:58 BST, Alex Wells wrote: >Thanks for explaining it better than I did. > >Regarding the implementation, that was roughly what I was thinking. > >But can't we put extension methods second, after real methods but before >__call? As far as I understand, the reason to put it af

Re: [PHP-DEV] Re: [Concept] Extension methods

2022-08-10 Thread Michał Marcin Brzuchalski
Hi Rowan, śr., 10 sie 2022 o 19:32 Rowan Tommins napisał(a): > On Wed, 10 Aug 2022 at 17:18, Ben Ramsey wrote: > > > I believe this is also called "monkey patching" in some places, and > > Ruby, Python, and JavaScript all offer some form of object extension > > similar to this. > > > > There is

Re: [PHP-DEV] Re: [Concept] Extension methods

2022-08-10 Thread Alex Wells
Thanks for explaining it better than I did. Regarding the implementation, that was roughly what I was thinking. But can't we put extension methods second, after real methods but before __call? As far as I understand, the reason to put it after __call is to avoid a performance penalty on __call ca

Re: [PHP-DEV] Re: [Concept] Extension methods

2022-08-10 Thread Rowan Tommins
On Wed, 10 Aug 2022 at 17:18, Ben Ramsey wrote: > I believe this is also called "monkey patching" in some places, and > Ruby, Python, and JavaScript all offer some form of object extension > similar to this. > > There is also the PHP runkit extension that provides some of the > functionality you'

Re: [PHP-DEV] Re: [Concept] Extension methods

2022-08-10 Thread Alex Wells
Sorry, replying to all this time :) I've missed to pinpoint an important fact: extensions don't add methods to types per-say, rather they allow using them when imported. Extension's methods would never be called if the extension isn't imported, which is different from monkey-patching and runkit, w

[PHP-DEV] Re: [Concept] Extension methods

2022-08-10 Thread Ben Ramsey
On 8/10/22 09:17, Alex Wells wrote: The idea is to introduce extension methods, similar to those in Kotlin, C#, Dart. For those unfamiliar, those are just regular functions with fancy syntax. However, I think having those will not only improve readability, but also cover some of the previously r

Re: [PHP-DEV] [Concept] Extension methods

2022-08-10 Thread Alex Wells
I believe disallowing multiple extensions on one type defeats one of the purposes of the feature - extending from outside. Let's say you have a vendor package for manipulating strings which defines an extension on `string` type. It works, but then you need one more custom extensions - some kind of

Re: [PHP-DEV] [Concept] Extension methods

2022-08-10 Thread Deleu
On Wed, Aug 10, 2022 at 5:16 PM Levi Morrison via internals < internals@lists.php.net> wrote: > > What are your thoughts? > > It's a fantastic feature that I've used in Rust, although there are > some differences. First, it doesn't work for regular methods -- they > have to be part of a trait. Sec

Re: [PHP-DEV] [Concept] Extension methods

2022-08-10 Thread Levi Morrison via internals
> What are your thoughts? It's a fantastic feature that I've used in Rust, although there are some differences. First, it doesn't work for regular methods -- they have to be part of a trait. Secondly, in general a trait can only be implemented for a given type if it is in the package which defines

[PHP-DEV] [Concept] Extension methods

2022-08-10 Thread Alex Wells
Hey internals. The idea is to introduce extension methods, similar to those in Kotlin, C#, Dart. For those unfamiliar, those are just regular functions with fancy syntax. However, I think having those will not only improve readability, but also cover some of the previously requested features. Say