Re: Re: Pre proposal for "Class extension functions"
| From: | Rasmus Schultz | Date: | Wed, 26 Sep 2018 15:57:29 +0000 |
| Subject: | Re: Re: Pre proposal for "Class extension functions" | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-103264@lists.php.net to get a copy of this message | ||
On Mon, Sep 24, 2018 at 11:24 PM Andrew Gromov <andrewgrom@rambler.ru> wrote:
> > Bring a little Javascript into PHP?
>
> In fact, I looked at Kotlin :)
Kotlin does not modify classes.
This sort of thing is sound in compiled languages like Kotlin and C#, where
this is really syntactic sugar for calling user-defined functions with
object-like
syntax - it's possible (and sound) *only* because these languages can resolve
such calls at compile-time.
In dynamic languages like JavaScript, you're literally writing to a
map of methods,
which means execution order is critical, and overwrites are possible - just two
reasons why this feature isn't sound in languages like JavaScript, and wouldn't
be in PHP either.
What's wrong with just calling a function and passing the object as argument?
In my opinion, this is the kind of pointless feature that brings nothing new and
invites inconsistent code and bikeshedding over pointless details.