What are some common pitfalls to avoid when working with XML files in PHP and storing values in variables?

One common pitfall when working with XML files in PHP is not properly handling errors that may occur during parsing or retrieving data from the file. To avoid this, it's important to use error handling techniques such as try-catch blocks to catch any exceptions that may be thrown.

try {
    $xml = simplexml_load_file('data.xml');
    $value = (string) $xml->node->subnode;
    // do something with $value
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}