Bug #3756
Empty SplObjectStorage property is not reconstituted
Status: | Rejected | Start date: | 2009-06-25 | |
---|---|---|---|---|
Priority: | Should have | Due date: | ||
Assigned To: | Karsten Dambekalns | % Done: | 100% |
|
Category: | FLOW3 Persistence | |||
Target version: | - |
Description
If a persisted object contains a property of type SplObjectStorage and that storage does not contain any objects, the storage itself won't be reconstituted on recreating the persisted object.
Example:
/** * A blog * * @scope prototype * @entity */ class Blog { /** * The posts contained in this blog * * @var \SplObjectStorage * @lazy */ protected $posts; /** * Constructs a new Blog */ public function __construct() { $this->posts = new \SplObjectStorage(); } /** * Adds a post to this blog * * @param \F3\Blog\Domain\Model\Post $post * @return void */ public function addPost(\F3\Blog\Domain\Model\Post $post) { $post->setBlog($this); $this->posts->attach($post); } /** * Returns all posts in this blog * * @return \SplObjectStorage * @author Robert Lemke <robert@typo3.org> */ public function getPosts() { if ($this->posts instanceof \F3\FLOW3\Persistence\LazyLoadingProxy) { $this->posts->_loadRealInstance(); } return clone $this->posts; } } ?>
If the Blog contains no Posts, getPosts() will return a clone of the empty SplObjectStorage. However, if the Blog has been reconstituted, $this->posts is NULL and therefore issues a fatal error on cloning $this->posts.
History
#1 Updated by Karsten Dambekalns about 6 years ago
- Status changed from New to Rejected
- % Done changed from 0 to 100
An SplObjectStorage instance is always persisted and restored, even when empty. The problem was caused by the fix for #3650 in r2640 - the posts member variable was never initialized and really contained NULL.
#2 Updated by Robert Lemke about 4 years ago
- Target version deleted (
0.5.0 alpha 2)