Override Method Which Use Private Variables

Hi! I newbie in OOP and Yii.


class A

{


public $z;

private $_a;


...


public function operation() {

$this->_a=5;

$this->z=1;

}


...


}

I need override only one method from class A without one line ($this->z=1;) .


class B extends A {


public $z;

private $_a;


...


public function operation() {

$this->_a=5;

}


...


}

How ? Behaviors?

Private variable are "private" and can not be changed directly from outside that class definition.

Usually private variables can be accessed through getters or setters already present. Or they have to be set indirectly (for example, the internal representation of speed may be in m/s and you have a setter that is in km/h).

In your case you could do this:




public function operation() {

   $orgZ=$this->z;

   parent::operation();

   $this->z=$orgZ;

}




Thx, and how about this case? Exist trick ?


class B extends A {


public $z;

private $_a;


...


public function operation() {

$this->z=1;

}


...


}



Your case is the trick: as you do not call the parent class, _a will not be modified in the parent class.