innerNode; } elseif ($this->firstChild !== null) { $node = Reflection::getProtectedProperty($this->firstChild, 'innerNode'); } if ($node !== null) { $doc = (!$node instanceof InnerDocument) ? $node->ownerDocument : $node; do { $next = $node->nextSibling; $wrapperNode = $doc->getWrapperNode($node); $result = ($filter === null) ? true : $filter($wrapperNode); if ($result === true) { yield $wrapperNode; } // If the filter returns true (accept) or false (skip) and the node wasn't // removed in the filter iterate through the children if ($result !== null && $node->parentNode !== null && $node->hasChildNodes()) { yield from $node->walk($filter); } } while ($node = $next); } } }