Hello,
I have a class with lots of members - some of them are plain numbers, some of them are arrays (multidimensional), some of them are other classes (some containing even more classes). So this is kinda rich class. I have several objects of it. I want to have all the properties of these objects summed in another object of the same type.
Here is a faint example of what I want:
Code:
class Foo {
public $a, $b, $c = array('c1' => 0, 'c2' => 0, 'c3' => 0);
}
class Bar {
public $d, $e = array(array()), $f = new Foo();
}
$obj1 = new Bar();
$obj1->f->a = 1;
// fill some data
$obj2 = new Bar();
$obj2->f->a = 5;
// fill some data
$obj3 = $obj1 + $obj2;
// at this point have $obj3->f->a = 6;
These are more complex structures with about 30-40 numbers, so I'm trying to avoid writing the addition of every member. Is there a PHP way to do this without much pain?