You can achieve this best by using the setter method.
class MyClass { private MyProperty; public function setMyProperty($value) { $this->MyProperty = $value; echo "MyProperty changed to " . $this -> MyProperty; } }
Now you just call the setter, rather than setting the value yourself.
$MyObject = new MyClass; $MyObject -> setMyProperty(1);
Fanax source share