Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bug #15906 Forbid serializing a Crawler (stof)
This PR was merged into the 2.3 branch.

Discussion
----------

Forbid serializing a Crawler

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Unserializing a Crawler instance creates DOM elements in an invalid state, making the Crawler unusable.
While working on #15849, I figured out that DomCrawler actually inherits ``Serializable`` from its ``SplObjectStorage`` parent, and so I tried to serialize and unserialize one. The answer is that it does not work. This is what happens when trying to call ``parents`` on it for instance:

```
Symfony\Component\DomCrawler\Crawler::parents(): Invalid State Error
```

Commits
-------

12733cb Forbid serializing a Crawler
  • Loading branch information
fabpot committed Sep 27, 2015
2 parents 2bd0738 + 12733cb commit 92a9e22
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Symfony/Component/DomCrawler/Crawler.php
Expand Up @@ -311,6 +311,17 @@ public function addNode(\DOMNode $node)
}
}

// Serializing and unserializing a crawler creates DOM objects in a corrupted state. DOM elements are not properly serializable.
public function unserialize($serialized)
{
throw new \BadMethodCallException('A Crawler cannot be serialized.');
}

public function serialize()
{
throw new \BadMethodCallException('A Crawler cannot be serialized.');
}

/**
* Returns a node given its position in the node list.
*
Expand Down

0 comments on commit 92a9e22

Please sign in to comment.