RE: [PHP-DEV] [RFC] Propety Accessors v1.1
| From: | Clint Priest | Date: | Tue, 09 Oct 2012 01:10:43 +0000 |
| Subject: | RE: [PHP-DEV] [RFC] Propety Accessors v1.1 | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-63288@lists.php.net to get a copy of this message | ||
Seems a fair amount of people would like it with a definable parameter name, though the original RFC
I based mine off of is more than 4 years old (mine is over a year old already).
The $value is precisely chosen because it is exactly the way C# operates and the original author
thought to keep it the same as another well-known language (why re-invent new syntax for no reason).
That being said, javascript does indeed allow it, my concern then would be would we have the
parameterized syntax only for set() and not get, isset or unset?
If we do have them for all of them, it's a lot of extra characters with no real need.
I definitely favor set($value) over a magic $Hours for the $Hours property, but I personally see no
problem with the $value, it's not magic it's a locally defined variable.
Internally, this:
public $Hours {
get { ... }
set { ... }
}
Is implemented as standard functions, while they are hidden through reflection, these functions
exist (as a result of the above example):
public __getHours() { ... }
public __setHours($value) { ... }
Lastly, with regards to JavaScript style getters/setters, I don't think I've ever cared
what the variable name was, I typically just do something like:
set blah(x) { ... } <-- x is fairly irrelevant and similarly the use of $value is fairly
irrelevant. Thoughts?
> -----Original Message-----
> From: Jazzer Dane [mailto:tbprogrammer@gmail.com]
> Sent: Monday, October 08, 2012 5:32 PM
> To: Benjamin Eberlei
> Cc: Aaron Holmes; internals@lists.php.net
> Subject: Re: [PHP-DEV] [RFC] Propety Accessors v1.1
>
> I agree.
> It's more consistent than the $Hours solution and we don't have to add another
> superglobal or magic constant, which is quite nice. The
> typehinting is a big plus as well.
>
> On Mon, Oct 8, 2012 at 3:26 PM, Benjamin Eberlei <kontakt@beberlei.de>wrote:
>
> > The set() one is really nice with the typehints.
> >
> > On Tue, Oct 9, 2012 at 12:19 AM, Aaron Holmes <aaron@aaronholmes.net>
> > wrote:
> >
> > > On 10/8/12 1:07 PM, Denis Portnov wrote:
> > >
> > >> 08.10.2012 15:52, Clint Priest пишет:
> > >>
> > >>> public $Hours {
> > >>> get { return $this->Seconds / 3600; }
> > >>> set { $this->Seconds = $value; }
> > >>>
> > >>> isset<http://www.php.net/isset**> { return isset<
> > >>>
> > >>> http://www.php.net/isset**>($this->Seconds); }
> > >>>
> > >>> unset<http://www.php.net/unset**> { unset<
> > >>> http://www.php.net/unset**5n˜îÛ
> > >>> £»‹Ön–z|õZ>($this->Seconds); }
> > >>> }
> > >>>
> > >>
> > >>
> > >> Hi Clint,
> > >>
> > >> I've noticed some magic variable '$value' is introduced. And
> > >> except
> > >> for superglobals I guess there is no such thing in PHP, so it looks
> > >> bit puzzling to me. I'd suggest on of the following:
> > >>
> > >>
> > >> - setter resambles setter method, wich also allows typehinting
> > >> public $Hours {
> > >> set ($value) { $this->Seconds = $value * 3600; }
> > >> }
> > >>
> > >> public $Hours {
> > >> set (DateTime $dateTime) { $this->Seconds =
> > >> $dateTime->getTimestamp(); }
> > >> }
> > >>
> > >> This seems like the cleanest method, in my opinion. Javascript
> > >> does
> > this
> > > for object prototypes:
> > >
> > > http://ejohn.org/blog/**javascript-getters-and-**setters/<
> > http://ejohn.org/blog/javascript-getters-and-setters/>
> > >
> > >
> > >>
> > >> What do you think?
> > >>
> > >> Thanks
> > >> Denis
> > >>
> > >>
> > >
> > > --
> > > PHP Internals - PHP Runtime Development Mailing List To unsubscribe,
> > > visit: http://www.php.net/unsub.php
> > >
> > >
> >