What I do wrong when creating objects?

Understand this important concept of OOP and use it in php. The theory has already read kind of figured. But as it came to practice he came up with Chet stuck. So the essence of the problem and my solution.
There is a xml which keeps the apartment complexes, they are in their own houses, then apartments (but will stop at the first).
The structure of the following
<complexes>
<complex>
<id>1</id>
 <name>LCD 1</name>
<complex>
<complex>
<id>2</id>
 <name>LCD 2</name>
<complex>
<complexes>

Fields a lot more, but I don't want them. Wanted to gather your property where will these fields with their names of the object properties.
Create a class "complex" and "Complex".
class Complexes {
 private $known = array();

 public function addComplex($id, $complex) {
 $this->reputation[$id] = $complex; 
}

 public function showComplexes() {
print_r($this);
}
}
class Subject {
 protected $id;
 protected $name;

 function __construct($subject) {
 $this->id = $subject->id;
 $this->name = $subject->name;
}

 public function var_d() {
print_f($this);
}

}

Create an object "Complexes"
$reputation = new Reputation();
Then in a loop run systems, create objects (as they further treated) and add in "Complexes"
foreach($xml as $c => $complex) { 
 $complexObj = new Subject($complex);

 // what your doing here

 $reputation->addComplex($complex->id, $complexObj);
}

At the end of trying to get so
$reputation->showComplexes();
And the array is empty

But if in the loop to put the output $complexObj->var_d(); all the rules, but the structure is a bit strange (at least for me)
Subject Object
(
 [id:protected] => SimpleXMLElement Object
(
 [0] => 1
)

 [name:protected] => SimpleXMLElement Object
(
 [0] => LCD 1
)
)
Subject Object
(
 [id:protected] => SimpleXMLElement Object
(
 [0] => 2
)

 [name:protected] => SimpleXMLElement Object
(
 [0] => LCD 2
)
)
March 12th 20 at 08:06
2 answers
March 12th 20 at 08:08
Solution
$this->id = (string) $subject->id[0];
$this->name = (string) $subject->name[0];
March 12th 20 at 08:10
Solution
$reputation->addComplex((int)$complex->id, $complexObj);
And designer Subject
$this->id = (int)$subject->id;
$this->name = (string)$subject->name;

Why is it so?? make var_dump($complex->id) or $complexObj and understand.

Find more questions by tags OOPPHP