I would like to accomplish the following - whenever a public property of an object is set, preferably only outside the class, I want a given function to be called that could for example change the value before assignment or log the fact of assigning somewhere else:
Code:
$obj = new MyClass;
$obj->var = 'value';
At this point I would like some other method to be called behind the scenes that will be passed the name and the new value of the property being set. It would even be ok, if
Code:
$obj->var = 'value';
would secretly invoke
Code:
$obj->var('value');
I know there is a magic method __set() but it seems to work only on non-existent properties while I want this to work when setting any property. Is this possible? I've heard of some magic possible with SPL or Reflection but couldn't find anything specific for this.