You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In general, you should not expect that you can modify a node after appending it to another this way.
That's because DOMDocument::importNode() which is used by append() internally always makes copies of the node objects. The Crawler object that is passed to append() gets updated with the cloned nodes (that's why it works in your first example) but any children of the nodes in the Crawler object are clones, too, and therefore not connected to Crawler objects that contained their originals any more.
In your example:
At line $rootNode1->append($testNode1); the p node inside $testNode1 is cloned when being appended to $rootNode1 but the $testNode1 object is updated to contain the cloned p node, so you can modify it afterwards.
In your second example, when calling $rootNode2->append($p); the $p variable will be updated with the cloned p node but the span child of it is not connected to the $testNode2 variable any more.
If someone has a suggestion how to fix this please contribute...
Please review the following test code. Am I doing something wrong here?
The text was updated successfully, but these errors were encountered: