Here is a slight modification to show the exact problem with using private:
Code: Select all
<?php
class A
{
private $var = 1;
function setVar ($val)
{
$this->var = $val;
}
function getVar ()
{
return $this->var;
}
}
class B extends A
{
function setVar ($val)
{
$this->var = $val;
echo "var set!\n";
}
}
$a = new A;
$b = new B;
$a->setVar('a');
print $a->getVar()."\n";
$b->setVar('b');
print $b->getVar()."\n";
?>Code: Select all
a
var set!
1Code: Select all
<?php
class A
{
private $var = 1;
function setVar ($val)
{
$this->var = $val;
}
function getVar ()
{
return $this->var;
}
}
class B extends A
{
function setVar ($val)
{
$this->var = $val;
echo "var set!\n";
}
function getVar ()
{
return $this->var;
}
}
$a = new A;
$b = new B;
$a->setVar('a');
print $a->getVar()."\n";
$b->setVar('b');
print $b->getVar()."\n";
?>Code: Select all
a
var set!
b