How can the error message "Creating default object from empty value" be avoided when assigning values to SimpleXML objects in PHP?

When assigning values to SimpleXML objects in PHP, the error message "Creating default object from empty value" can be avoided by explicitly creating the object before assigning values to it. This can be done by using the `new SimpleXMLElement()` constructor to create an instance of the SimpleXML object before setting any values.

// Create a new SimpleXMLElement object
$xml = new SimpleXMLElement('<root></root>');

// Assign values to the SimpleXMLElement object
$xml->addChild('name', 'John Doe');
$xml->addChild('age', 30);

// Output the XML
echo $xml->asXML();