如何在编辑类var时运行函数

I've done recently an account system and i want to do it again properly in OOP. I've almost finished the class usr but i want (when the user change the value of "avatarURL") to run a little function to update the value in the database. Something like:

class usr{
  public $username, $mail, $password // [...]

  function __construct($username){
  // I initialize the mail, password, avatar URL and the Session
  }

  function(){ /* To run if $this->avatarURL is edited */
    // Check if is correct value first and then something like :
    $bdd= new PDO(...);
    $sql = $bdd->prepare('UPDATE `avatarURL` IN `accounts` WHERE `username`=?');
    $sql->execute(array(*newValue*));
  }
}

I'm almost sure that's possible i just don't know how and i haven't found anything helpful on my Google so...