2010/11/29 Ángel González <keis...@gmail.com>:
> Richard Quadling wrote:
> setMilliseconds() should have $value as parameter instead of a magic name.
>
> What about allowing this syntax to attach the property to a variable?
>
> For instance:
>
> <?php
> class TimePeriod
> {
>    protected $seconds;
>    protected $minutes;
>    protected $hours;
>
>    public property Seconds read $seconds write setSeconds;
>    public property Minutes read $seconds write setMinutes;
>    public property Hours read $seconds write setHours;
>
>    public function setSeconds($seconds)
>    {
>        if ($seconds >= 0 && $seconds < 60) $this->seconds = $seconds;
>    }
>
>    public function setMinutes($minutes)
>    {
>        if ($minutes >= 0 && $minutes < 60) $this->minutes = $minutes;
>    }
>
>    public function setHours($hours)
>    {
>        if ($hours >= 0 && $hours < 24) $this->hours = $hours;
>    }
>
> }
>
> We only want to perform checks on write, so instead of writing the trivial
> getters, the property is set to the variable itself. Child classes could
> reattach it to a function if needing more control.

Ouch. I messed up on the example code. Completely forget that there
was a parameter to process...

As for reading $seconds directly ...

Well.

If you think of the element that follows read as $this->xxxx, then if
the parser can handle both ...

read $seconds
read getSeconds

then yes for both.

If not, then I'd guess that the getSeconds version should be the one
we use as the value may not actually exist without some processing.

Richard.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to