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

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -