PHP 8.5.0 Alpha 4 available for testing

Voting

: two minus two?
(Example: nine)

The Note You're Voting On

h-fate at gmx dot net
10 years ago
If you have an object that holds a DOMNode, cloning the object won't clone the DOMNode with it. If you simply copy the object or add its DOMNode several times, you will in fact only move the DOMNode in the tree, not multiply it. That might seem obvious, but took me half a day to find out.

The object needs to use __clone and clone the node manually:

<?php
class containsNode {
public
$node; //set from somewhere

public function __clone() {
$this->node = $this->node->cloneNode(TRUE);
}
}
?>

<< Back to user notes page

To Top