On Oct 8, 2012, at 10:07 PM, Denis Portnov <[email protected]> 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>($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:
>
> - variable for value has the same name as property
> public $Hours {
> set { $this->Seconds = $Hours * 3600; }
> }
>
> - magic constant
> public $Hours {
> set { $this->Seconds = __VALUE__ * 3600; }
> }
>
> - 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();
> }
> }
If this function inspired syntax is used, then it kind of hints the possibility
of future parameter overloading, like:
public $Hours {
set ( DateTime $dateTime ) { $this->Seconds = $dateTime->getTimestamp(); }
set ( int $hours ) { $this->Seconds = $hours*60*60; }
}
So for me +1 on that syntax, or using/future-proofing for the syntax from C#:
public DateTime $Hours {
set { $this->Seconds = $value->getTimestamp(); }
}
However the example doesn't make much sense (hours being datetime).
>
> - or at least have it in same format as superglobals
> public $Hours {
> set { $this->Seconds = $_VALUE * 3600; }
> }
>
> What do you think?
>
> Thanks
> Denis
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>