php - Change value of a variable of the parent class in the child class -
class { protected $a; // code } class b extends { // code } how can edit protected value of variable $a inside b class ?
i'm trying use parent::$a = "some value" doesn't work.
protected instance properties, not declared using static, can accessed in subclasses using $this :
class { protected $a; // code } class b extends { // code public function edit($val) { $this->$a = $val; echo "a {$this->a}\n"; } } call:
$b = new b(); $b->edit('foo'); // foo refer manual, examples.
Comments
Post a Comment