Re: Patch: getters/setters syntax Implementation
| From: | Rasmus Schultz | Date: | Wed, 07 Dec 2011 17:50:14 +0000 |
| Subject: | Re: Patch: getters/setters syntax Implementation | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-56836@lists.php.net to get a copy of this message | ||
> if we're attempting to get around __set/get, let's not replace them with
more method implementations
I don't understand this argument. Accessors are methods - making them look
like something else won't change that fact.
In C#, type-hinted properties with automatic getters/setters actually
compile down to two method implementations, while implemented
getters/settings do the same, substituting "value" for whatever is required
to access the auto-implemented backing field.
On Tue, Dec 6, 2011 at 9:26 AM, Will Fitch <will.fitch@gmail.com> wrote:
>
> On Dec 6, 2011, at 8:58 AM, Rasmus Schultz wrote:
>
> > I agree with all of those points - the extra indentation looks messy, and
> > yes, type hints are important. It does fit better with PHP in general.
> >
> > It would be nice to also have support for automatic backing fields in
> > addition though - so something simple like this:
> >
> > class BlogPost
> > {
> > private $_author;
> >
> > public get author()
> > {
> > return $this->_author;
> > }
> >
> > public set author(Person $value)
> > {
> > $this->_author = $value;
> > }
> > }
>
> I don't like this approach. All efforts (which I'm currently part of) to
> implement type hinting return values will be compromised. If you want to
> implement accessors, keep them within a syntax that makes sense.
> Personally, I support the C# style as much as possible. Methods are
> already overused for purposes they shouldn't be, so if we're attempting to
> get around __set/get, let's not replace them with more method
> implementations.
>
>