properties - Assigning Values to a Class Property in PHP -


one of examples in php book learning (illustrating private properties) starts this:

class account {    private $_totalbalance = 0;     public function makedeposit($amount) {       $this->_totalbalance+= $amount;    }     public function makewithdrawal ($amount){       if ($amount < $this->_totalbalance) {          $this->_totalbalance -= $amount;       }       else {          die("insufficient funds <br />" );       }    }    public function gettotalbalance() {       return $this->_totalbalance;    } }  $a = new account; $a->makedeposit(500); $a->makewithdrawal(100); echo $a->gettotalbalance(); $a->makewithdrawal(1000); ?> 

my question is, why $_totalbalance property assigned value in class rather object? wouldn't want value of $totalbalance specific object?

thanks help.

when call $a->makedeposit(), inside makedeposit() $this same $a. if had instance ($b = new account;) calling $b->makedeposit() mean $this same $b.


Comments