Re: [RFC] Property Accessors v1.2 : Extra shorthand declaration

From: Date: Sat, 27 Oct 2012 17:42:31 +0000
Subject: Re: [RFC] Property Accessors v1.2 : Extra shorthand declaration
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-63668@lists.php.net to get a copy of this message
On 10/26/2012 9:39 AM, Stas Malyshev wrote:
Hi!
/* Would be equivalent to this */ class TimePeriod {
      public $date {
          get() { return $this->date; }
          set(DateTime $value) { $this->date = $value;}
      }
}
I don't think this has a use case and this encourages mixing variables with properties (which I'm not sure is a very good idea) and writing slower and more complicated code which doesn't actually do any additional work. I'd rather not encourage it. If you want it - fine, implement it, but I don't think supporting it is good. I would agree that it should not be in here, AFAIK only Nikita was pushing for this... anyone else want to fight to have this functionality?
Also, "get() { return $this->date; }" implies there is a thing called "$this->date" which is not the property itself. So what is it? Should there be additional "public $date;" declaration in your code? Is it implied that property definition also creates a variable inside class automatically - I was under expression this does not happen, and nothing in the RFC implies it. Should it be $this->__date maybe like in "automatic accessors" part of the RFC? This is related to accessors shadowing properties, if that's the case then $this->date would retrieve an actual property named date (and since it's shadowed by the accessor it could never be accessed from outside the accessor. See the shadowing thread.
-- -Clint

« previous php.internals (#63668) next »