What is the common mistake made when using foreach with SimpleXML in PHP?

When using foreach with SimpleXML in PHP, a common mistake is trying to directly iterate over the SimpleXMLElement object itself. Instead, you should access the children of the SimpleXMLElement object using the children() method before iterating over them. This is because SimpleXMLElement objects do not behave like standard arrays.

$xml = simplexml_load_file('data.xml');

foreach ($xml->children() as $child) {
    // Process each child element here
}