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

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -