php magic setters - modified child properties -
lets say, have following php class:
class product { protected $data = array(); protected $modified = false; public function __construct($data) { $this->data = $data; } public function & __get($name) { if(array_key_exists($name, $this->data)) { return $this->data->$name; } $null = null; return $null; } public function __set($name, $value) { $this->data->$name = $value; $this->modified = true; } } $obj = new product([]);
if set value (for example $obj->name = "name";
), class property $modified set true. thats want achive.
but somehow possible, "track" modifications, if done in object values? example:
$property = new stdclass(); $property->name = "name of prop"; $obj = new product([ "name" => "name", "someobject" => $property ]); // here comes change $obj->someobject->name = "new name";
because code above, $obj->modified false
i guess, have pass new value "set" function. way changes value without going function declared, "modified" turns true.
like maybe?
$obj->someobject->__set($name, 'new name');
Comments
Post a Comment