Question

When I run this code, About half-way through the concatenation loop, $xml becomes null and remains null throughout the rest of the concatenation loop. Has anyone see why this is happening?

$xml = '';
foreach($this->currentColumns['unknown'] as $column => $value)
{
   $xml .= "<columnName>";
   $xml .= $column;
   $xml .= "</columnName>\r\n";
}
return $xml;
Was it helpful?

Solution

In case $this->currentColumns is some kind of result of an XML parsing (with SimpleXML for instance), it's very possible that the elements of this array are not really strings, but XMLElement objects, or something close enough.

Try casting your variable, so you're sure you're catenating strings and not objects :

$xml = '';
foreach($this->currentColumns['unknown'] as $column => $value)
{
   $xml .= "<columnName>";
   $xml .= (string)$column;  // <--- here is the trick
   $xml .= "</columnName>\r\n";
}
return $xml;

OTHER TIPS

You're going to have to print out your $column values as you go. If you're getting a very unexpected column name, you might have to test on that condition before creating the xml string for it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top