Re: [RFC] Propety Accessors v1.1
| From: | Denis Portnov | Date: | Mon, 08 Oct 2012 20:07:41 +0000 |
| Subject: | Re: [RFC] Propety Accessors v1.1 | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-63284@lists.php.net to get a copy of this message | ||
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(); }
}
- or at least have it in same format as superglobals
public $Hours {
set { $this->Seconds = $_VALUE * 3600; }
}
What do you think?
Thanks
Denis