php - extending classes issue -
i have master class several separate classes want link can share variables defined in master class. problem first slave class can read $x variable, every subsequent slave class (i have 20 others) shows $x blank. example:
class master { var $x; function initialize{) { $this->x = 'y'; } } class slave1 extends master { function process(){ echo $this->x; } } class slave2 extends master { function process(){ echo $this->x; } }
am doing wrong here? i've never used extended classes before i've no idea i'm doing :)
class master { var $x; // should use protected or public function __construct() { $this->initialize(); } function initialize{) { $this->x = 'y'; } } class slave1 extends master { function process(){ echo $this->x; } } class slave2 extends master { function process(){ echo $this->x; } }
Comments
Post a Comment