Programming Tutorials

Comment on Tutorial - public, protected, and private Properties in PHP By Andi, Stig and Derick



Comment Added by : Neeraj

Comment Added at : 2010-10-22 07:23:56

Comment on Tutorial : public, protected, and private Properties in PHP By Andi, Stig and Derick
i disagree that private variables can be accessed from derived class. The below code runs perfectly.

<?php
class a{

private $name;

public function setval($val){
$this->name = $val;
echo $this->name." 1<BR>";
}
}

class b extends a{

private $name1;

public function setval($val){
$this->name = $val;
echo $this->name." 2<BR>";
}
}

class c extends b{
private $name2;

public function setval($val){
$this->name = $val;
echo $this->name." 3<BR>";
}
}

class d extends c{
private $name3;

public function setval($val){
$this->name = $val;
echo $this->name." 4<BR>";
}
}

$obj1 = new a();
$obj1->setval(5);
$obj2 = new b();
$obj2->setval(10);
$obj3 = new c();
$obj3->setval(20);
$obj4 = new d();
$obj4->setval(30);
?>


View Tutorial