I've updated the RFC to include details on adding isset/unset as well as
references, detailed below:
isset/unset:
class TimePeriod {
private $Seconds = 3600;
public $Hours {
get { return $this->Seconds / 3600; }
set { $this->Seconds = $value; }
isset { return !is_null($this->Seconds); }
unset { $this->Seconds = NULL; }
}
}
References:
class SampleClass {
private $_dataArray = array(1,2,5,3);
public $dataArray {
&get { return &$this->_dataArray; }
}
}
$o = new SampleClass();
sort($o->dataArray);
/* $o->dataArray == array(1,2,3,5); */
Comments?
These would also include automatic implementations which call the respective
functions on the backing field. I could see only allowing isset/unset
automatic implementations if get/set were also specified as automatic
implementations.
Default implementations of isset/unset
I'm also fielding comments/ideas on a way to always provide automatic
implementations of isset/unset for any accessor that didn't define one
automatically. One idea was for the isset (unspecified implementation) which
would return true if the getter provided any value which evaluated to true,
such as this:
class TimePeriod {
private $Seconds = 3600;
public $Hours {
get { return $this->Seconds / 3600; }
set { $this->Seconds = $value; }
}
}
/* Default Implementation Concept */
isset { return (int)$this->Hours; }
unset { $this->Hours = NULL; }
Note that the automatic implementation of unset is not strictly the same as an
unset() but without any sort of unset implementation a call to unset() would do
nothing. Alternatively we could throw an error to a call on isset and/or unset
against a property which didn't define an implementation.
Thoughts?
-Clint