diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index a5a1ba374b..0e4277914d 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -313,14 +313,6 @@ class Crawler extends \SplObjectStorage */ public function addNode(\DOMNode $node) { - if (null !== $this->document && $this->document !== $node->ownerDocument) { - @trigger_error('Attaching DOM nodes from multiple documents in a Crawler is deprecated as of 2.8 and will be forbidden in 3.0.', E_USER_DEPRECATED); - } - - if (null === $this->document) { - $this->document = $node->ownerDocument; - } - if ($node instanceof \DOMDocument) { $node = $node->documentElement; } @@ -329,6 +321,14 @@ class Crawler extends \SplObjectStorage throw new \InvalidArgumentException(sprintf('Nodes set in a Crawler must be DOMElement or DOMDocument instances, "%s" given.', get_class($node))); } + if (null !== $this->document && $this->document !== $node->ownerDocument) { + @trigger_error('Attaching DOM nodes from multiple documents in a Crawler is deprecated as of 2.8 and will be forbidden in 3.0.', E_USER_DEPRECATED); + } + + if (null === $this->document) { + $this->document = $node->ownerDocument; + } + parent::attach($node); }