If I have a subclass that is overriding a protected variable, and the parent class has the function to do stuff with that variable, how do I get that function to use the value it is overridden with?
class Superclass {
protected $map;
public function echoMap()
{
foreach ($this->map as $key=>value)
{
echo "$key:$value";
}
}
}
and
class Subclass extends Superclass {
protected $map = array('a'=>1, 'b'=>2);
}
and when I run the following
$subclass = new Subclass();
$subclass->echoMap();
I would expect it to return
a:1
b:2
but $this->map
is empty in the parent class. What should I do instead to get the behavior I want?
Edit: There was a bug in the constructors, not in the example posted above. It works as expected.