QueryPath\DOMQuery::branch PHP Method

branch() public method

This function makes a copy of the DOMQuery object, but keeps the new copy (initially) pointed at the same matches. This object can then be queried without changing the original DOMQuery. However, changes to the elements inside of this DOMQuery will show up in the DOMQuery from which it is branched. Compare this operation with {@link cloneAll()}. The cloneAll() call takes the current DOMNode object and makes a copy of all of its matches. You continue to operate on the same DOMNode object, but the elements inside of the DOMQuery are copies of those before the call to cloneAll(). This, on the other hand, copies the DOMQuery, but keeps valid references to the document and the wrapped elements. A new query branch is created, but any changes will be written back to the same document. In practice, this comes in handy when you want to do multiple queries on a part of the document, but then return to a previous set of matches. (see {@link QPTPL} for examples of this in practice). Example:
See also: cloneAll()
See also: find()
Since: 1.1
public branch ( string $selector = null )
$selector string If a selector is passed in, an additional {@link find()} will be executed on the branch before it is returned. (Added in QueryPath 2.0.)
    public function branch($selector = null)
    {
        $temp = \QueryPath::with($this->matches, null, $this->options);
        //if (isset($selector)) $temp->find($selector);
        $temp->document = $this->document;
        if (isset($selector)) {
            $temp->findInPlace($selector);
        }
        return $temp;
    }