NodeList is only array like. Removing items using foreach() has undesired results.

@return NodeList
351638
public function contents(): NodeList {
        $results = $this->collection()->reduce(function($carry, $node) {
            if ($node->isRemoved()) {
                return $carry;
            }

            return $carry->merge(
                $node->newNodeList($node->childNodes)
            );
        }, $this->newNodeList());

        return $results;
    }
368640
public function children()
    {
        if (!$this->nodes) {
            throw new \InvalidArgumentException('The current node list is empty.');
        }

        $node = $this->getNode(0)->firstChild;

        return $this->createSubCrawler($node ? $this->sibling($node) : array());
    }
102351
public function links()
    {
        $links = array();
        foreach ($this->nodes as $node) {
            if (!$node instanceof \DOMElement) {
                throw new \InvalidArgumentException(sprintf('The current node list should contain only DOMElement instances, "%s" found.', get_class($node)));
            }

            $links[] = new Link($node, $this->baseHref, 'get');
        }

        return $links;
    }
260968
public function siblings()
    {
        if (!$this->nodes) {
            throw new \InvalidArgumentException('The current node list is empty.');
        }

        return $this->createSubCrawler($this->sibling($this->getNode(0)->parentNode->firstChild));
    }
342778
public static List<Element> convertToElementList(org.w3c.dom.NodeList _nodeList) {
        List<org.w3c.dom.Element> elemList = new ArrayList<>();
        for (int i = 0; i < _nodeList.getLength(); i++) {
            Element elem = (org.w3c.dom.Element) _nodeList.item(i);
            elemList.add(elem);
        }
        return elemList;
    }
691781
public function toArray(){
		$array	= array();
		foreach( $this->data as $key => $node ){
			if( count( $node->data ) )
				$array[$key]	= $node->toArray();
			else
				$array[$key]	= $node->value;
		}
		return $array;
	}
369078
public static <T> List<T> toList(final NodeList nodes) {
        final List<T> res = new ArrayList<>(nodes.getLength());
        for (int i = 0; i < nodes.getLength(); i++) {
            res.add((T) nodes.item(i));
        }
        return res;
    }
623973
public function getLists () {
		// Query Sharepoint for full listing of it's lists.
		$rawXml = '';
		try {
			$rawXml = $this->soapClient->GetListCollection()->GetListCollectionResult->any;
		} catch (\SoapFault $fault) {
			$this->onError($fault);
		}

		// Load XML in to DOM document and grab all list items.
		$nodes = $this->getArrayFromElementsByTagName($rawXml, 'List');

		// Format data in to array or object
		foreach ($nodes as $counter => $node) {
			foreach ($node->attributes as $attribute => $value) {
				$idx = ($this->lower_case_indexs) ? strtolower($attribute) : $attribute;
				$results[$counter][$idx] = $node->getAttribute($attribute);
			}

			// Make object if needed
			if ($this->returnType === 1) {
				settype($results[$counter], 'object');
			}
		}

		// Add error array if stuff goes wrong.
		if (!isset($results)) {
			$results = array('warning' => 'No data returned.');
		}

		return $results;
	}
79577
public NodeList nodelist() throws javax.xml.transform.TransformerException
  {

    error(XPATHErrorResources.ER_CANT_CONVERT_TO_NODELIST,
          new Object[]{ getTypeString() });  //"Can not convert "+getTypeString()+" to a NodeList!");

    return null;
  }
480455
private function _foreach() {
    $node = new ForeachNode();
    $this->mustMatch(T_FOREACH, $node);
    $this->mustMatch('(', $node, 'openParen');
    $node->addChild($this->expr(), 'onEach');
    $this->mustMatch(T_AS, $node);
    $value = $this->foreachVariable();
    if ($this->currentType === T_DOUBLE_ARROW) {
      $node->addChild($value, 'key');
      $this->mustMatch(T_DOUBLE_ARROW, $node);
      $node->addChild($this->foreachVariable(), 'value');
    }
    else {
      $node->addChild($value, 'value');
    }
    $this->mustMatch(')', $node, 'closeParen', FALSE, TRUE);
    if ($this->tryMatch(':', $node, NULL, FALSE, TRUE)) {
      $node->addChild($this->innerStatementListNode(T_ENDFOREACH), 'body');
      $this->mustMatch(T_ENDFOREACH, $node);
      $this->endStatement($node);
      return $node;
    }
    else {
      $node->addChild($this->statement(), 'body');
      return $node;
    }
  }
191171
public function AllChildrenIncludingDeleted()
    {
        $children = parent::AllChildrenIncludingDeleted();

        $filteredChildren = new ArrayList();

        if ($children) {
            foreach ($children as $child) {
                /** @var DataObject $child */
                if ($child->canView()) {
                    $filteredChildren->push($child);
                }
            }
        }

        return $filteredChildren;
    }
19795
public List children() {
        if (value == null) {
            return new NodeList();
        }
        if (value instanceof List) {
            return (List) value;
        }
        // we're probably just a String
        List result = new NodeList();
        result.add(value);
        return result;
    }
949154
public function getCheckedList()
    {
        $ids = array();
        foreach ($this->list as $id => $item) {
            if ($this->list[$id]['value'] === true) {
                $ids[] = $id;
            }
        }
        return $ids;
    }
1052073
public function sort()
    {
        foreach ($this->idDirectedGraph as $nodeId => $successorIds) {
            if (!isset($this->nodeMarks[$nodeId])) {
                $this->visit($nodeId);
            }
        }

        $sortedIdList = array_reverse($this->sortedIdList);

        $sortedNodeList = [];
        foreach ($sortedIdList as $nodeId) {
            $sortedNodeList[] = $this->idToNode[$nodeId];
        }

        return $sortedNodeList;
    }
1008484
public function resetNodeStats()
    {
        foreach ($this->nodeMap as &$nodeStat) {
            foreach ($this->nodeIncrements as $key => $value) {
                if (isset($nodeStat[$key])) {
                    $nodeStat[$key] = $value;
                }
            }
        }

        return $this;
    }
369613
public function clear() {
    foreach ($this->nodes as $node) {
      if ($node instanceof ParentNode) {
        $node->clear();
      }
    }
    return $this;
  }
776601
function nodeListToArray (nodes) {
    if ($.env.name !== 'IE' || $.env.version > 9) {
      return prototypeSlice.call(nodes);
    }

    // IE 9 and below call use Array.prototype.slice.call against
    // a NodeList, hence the following
    var array = [];

    for (var i=0, num=nodes.length; i<num; ++i) {
      array.push(nodes[i]);
    }

    return array;
  }