What are the common pitfalls when using appendChild with attributes in PHP?

When using `appendChild` with attributes in PHP, a common pitfall is mistakenly trying to set attributes directly on the element itself instead of creating a new attribute node and appending it to the element. To solve this issue, you should create a new attribute node using `createAttribute` method, set its value using `nodeValue`, and then append it to the element using `setAttributeNode`.

// Create a new attribute node
$attr = $dom->createAttribute('class');
// Set the value of the attribute
$attr->nodeValue = 'example-class';
// Append the attribute to the element
$element->setAttributeNode($attr);