oop - Generic setter function for local properties in PHP -
i'm planning log modifications properties of object.
php has magic method __set
overload attempts modify (private) properties outside object.
however, not apply inside object. is there way in php have generic setter function calls modify local propery of object?
example:
class thing { private $data; public function editdata() { $this->data = 'edited'; } function __magic($property, $value) { if ($property === 'data') { print 'data being edited!'; } } }
i want __magic
function called before $data
edited.
no, inside object properties accesible , don't need magic method. if want asign properties throw function, have slighty modification in code:
class thing { private $data; public function editdata() { $this->propertysetter('data', 'edited'); } function propertysetter($property, $value) { if ($property === 'data') { print 'data being edited!'; } $this->$property = $value; } }
Comments
Post a Comment