class Parent {
var $errorArray = array();
function Parent() {
return true;
}
function getErrorArray() {
return $this->errorArray;
}
function setErrorArray($errorArray) {
$this->errorArray = $this->errorArray + $errorArray;
}
}
class Child1 extends Parent {
function Child1() {
return true;
}
function doStuff() {
if ($this->isWrong) {
$this->setErrorArray(array('action' => 'Oops!'));
}
}
}
class Child2 extends Parent {
function Child2() {
return true;
}
function doStuff() {
if ($this->isWrong) {
$this->setErrorArray(array('action' => 'Oops!'));
}
}
}
$child1 =& new Child();
$child1->doStuff();
print_r($child1->getErrorArray());
$child1 = null;
$child2 =& new Child();
$child2->doStuff();
print_r($child2->getErrorArray());
$child2 = null;
[/PHP]
Ok, here is the simplest example of what I am trying to do. I have a
near-pure-OO required setup of PHP where I am performing a Child1
object instance method doStuff(). If something goes wrong it sets its
parents $this->errorArray. I will then perform a Child2 object
instance method doStuff(). Same rules apply.
I want to see both errors filled out when I do my print_r() commands,
but all I get is this:
Array ()What am I doing wrong in my structure? I want all of my children
classes of Parent all set up the same instance of $this->errorArray.
Does it need to be static? What do I do?
Phil