Re: Pre proposal for "Class extension functions"

From: Date: Tue, 25 Sep 2018 14:48:35 +0000
Subject: Re: Pre proposal for "Class extension functions"
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-103259@lists.php.net to get a copy of this message
On Tue, Sep 25, 2018 at 1:50 AM Stanislav Malyshev <smalyshev@gmail.com> wrote: > > I want to do RFS proposal for new language concept - Class extension > > functions. > > > > Syntax will looks like: > > > > function DateTime->localTime() { > > return $this->format('H:i'); > > } > > I feel this is inviting trouble. If you need additional functionality, > why not extend the class? Or write a function that accepts DateTime as > an argument? This encourages a style of programming where you never know > which object does what. Even in JS, as far as I know, it's not exactly > the recommended style. But in PHP I don't think we should be doing this. > I've been back-burnering this for a few days and I'm with Stas. I don't like this proposal because it adds complexity with relatively little benefit. If I wanted to add utility functions, I could create a proxy class which encapsulates the target and has a getter for passing into typehinted interfaces. You get all the functionality in any existing version of PHP without the added parser/engine complexity. Even static properties (which sadly lack get/set accessors) could be proxied using references so long as you know the statics ahead of time. -Sara

« previous php.internals (#103259) next »