[TYPO3-mvc] Problems with clearing an ObjectStorage

Sebastian Michaelsen sebastian.gebhard at gmail.com
Thu Jun 23 09:29:47 CEST 2011


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?


More information about the TYPO3-project-typo3v4mvc mailing list