There is a code for parsing an XML file into an object. But the problem is that when I try to pass a simpleXml object to the method, it scolds me in this way. Only variables should be passed by reference . I give a code sample just below. Swears exactly on the line calling parseTournaments
PS I forgot to clarify - $ this-> data is our root object, the nested object $ country is passed to the method
public function parseStruct() { $root = new Root(); foreach($this->data->sport as $sport) { $root->createSport($sport['name'], $sport['id']); foreach($sport->country as $country) { $root->createCountry($country['name'], $sport['id'], $country['id']); $sport_obj = end($root->getSports()); $country_obj = end($root->getCountries()); $this->parseTournaments($sport_obj, $country_obj, $country); } } return $root; }