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; } 

    1 answer 1

    Assign the explosion result to a variable and pass this variable to the end

     $tmp1 =$root->getSports(); $tmp2 = $root->getCountries(); sport_obj = end($tmp1); $country_obj = end($tmp2); 

    End works as a link, and in the current example it cannot convert an array into a link.