[TYPO3-mvc] Problems with clearing an ObjectStorage

Claus Due claus at wildside.dk
Thu Jun 23 09:37:01 CEST 2011


Hi Sebastian,

The behaviour you note there is caused by this being an Iterator and not an Array. They work quite differently.

There's a longer explanation why this is so with ObjectStorage here: http://forge.typo3.org/issues/13147

--

Med venlig hilsen / Kind regards

Claus Due
Code Monkey
--
Wildside A/S
Katrinebjergvej 113, DK-8200 Århus N
tlf. 86 12 64 65
http://www.wildside.dk

On Jun 23, 2011, at 9:29 AM, Sebastian Michaelsen wrote:

> Am 22.06.2011 17:14, schrieb Claus Due:
>> Hi Sebastian,
>> 
>> When you use getFavorites() you de-reference the variable. So, from inside the model:
> Mh, I thought in PHP objects are always passed by reference.. could be wrong..
> 
>> 
>> $this->favorites->removeAll($this->favorites);
> One item remains in the Storage.
> 
> 
> This is the original ObjectStorage->removeAll() method:
> 
> /**
> * Removes objects contained in another storage from the current storage.
> *
> * @param Tx_Extbase_Persistence_ObjectStorage $storage The storage containing the elements to remove.
> * @return void
> */
> public function removeAll(Tx_Extbase_Persistence_ObjectStorage $storage) {
> 	foreach ($storage as $object) {
> 		$this->detach($object);
> 	}
> }
> 
> I did a bit research and I found out that if I pass a $storage with 3 items, the foreach only iterates over 2 of them, ignoring 1 element to be removed. No idea why.
> 
> However if I change the foreach to
> 
> foreach ($storage->toArray() as $object)
> 
> it works.
> 
> Is it a bug in extbase or could I have made a mistake which could cause this?
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc



More information about the TYPO3-project-typo3v4mvc mailing list