Posted by Mads Lee Jensen on 10/04/07 15:18
is it the __set() purpose to be called if a property exists in the
object but is out of the scope.
or is it only to be used for 'undefined instance properties'.
test:
class Magic_Set
{
public $fornavn = '';
private $efternavn = '';
public function __set($varName, $value)
{
if (property_exists($this, $varName)) {
echo 'edit ['.$varName.'='.$this->$varName.']
to ['.$varName.'='.$value.']';
}
else {
echo 'defining ['.$varName.'='.$value.']';
}
$this->$varName = $value;
}
}
$test = new Magic_Set();
$test->fornavn = 'mads';
$test->efternavn = 'jensen';
$test->mellemnavn = 'lee';
[Back to original message]
|