Posted by C. on 08/01/07 16:36
On 29 Jul, 18:08, Rik <luiheidsgoe...@hotmail.com> wrote:
> On Sun, 29 Jul 2007 18:53:24 +0200, Jeff
>
>
>
> <it_consulta...@hotmail.com.NOSPAM> wrote:
> > I'm wondering if something similar is possible with
> > object-oriented PHP (5.2.3) programming??
>
>
>
> An implementation of this could be:
>
> <?php
> class Period{
> private $_second;
>
> function __set($name,$value){
> echo 'Setting '.$name;
> $this->$name = $value;
> }
> function __get($name){
> echo 'Getting '.$name;
> if(isset($this->$name)) return $this->$name;
> echo 'No such property: Period::'.$name;
> }}
>
> $foo = new Period();
> $foo->_second = 123;
> echo $foo->_second ;
> ?>
Which neatly demonstrates PHPs built in methods for objects - but is
probably overkill as a solution to the problem. I don't really
know .NET but I suspect this class stores a value and when a new value
is set it returns the previous value. In which case:
class Period
{
private $_second;
function Seconds($value)
{
$prev=$this->_second;
$this->_second=(double)$value;
return($prev);
}
}
C.
[Back to original message]
|