Bug #9117
ObjectStorage->toArray
| Status: | Resolved | Start date: | 2010-08-02 | |
|---|---|---|---|---|
| Priority: | Could have | Due date: | ||
| Assignee: | Claus Due | % Done: | 0% |
|
| Category: | Extbase: Generic Persistence | |||
| Target version: | Extbase 1.4 | |||
| Has patch: | No | Tags: | ||
| Votes: | 0 |
Description
When i try to use this function in my Controller, it returns an empty array...
I have to call rewind first...
Bug or Feature?
Related issues
| related to Extbase MVC Framework - Bug #13256: LazyObjectStorages should trigger "rewind" on initialization | Resolved | 2011-02-22 |
History
Updated by Thomas Maroschik almost 3 years ago
From my point of view definitely a bug. The problem with rewind is that you loose your cursor.
How would something like the following work:
/**
* Returns this object storage as an array
*
* @return array The object storage
*/
public function toArray() {
return array_values($this->storage);
}
instead of
/**
* Returns this object storage as an array
*
* @return array The object storage
*/
public function toArray() {
$array = array();
foreach ($this->storage as $item) {
$array[] = $item['obj'];
}
return $array;
}
we could use the power and speed of C ;)
Updated by Franz Koch over 2 years ago
Hey Thomas,
if you would have a closer look at the code you'd see that $this->storage is not just an array holding objects but an array holding another array per object with optional tag/description in a second array key. So using array_values wouldn't work here, or at least not return just the objects.
Updated by Marc Bastian Heinrichs over 2 years ago
Because toArray() uses an foreach internally there must not be an rewind called normally, but we should verify this with unit tests.
Updated by Marc Bastian Heinrichs over 2 years ago
- Priority changed from -- undefined -- to Could have
Updated by Marc Bastian Heinrichs over 2 years ago
- Category set to Extbase: Generic Persistence
- Assignee set to Marc Bastian Heinrichs
- Target version set to Extbase 1.4
Updated by Claus Due about 2 years ago
Fix submitted for review as change 533b9da in git repository for Extbase. A combination of both: array_values then iteration, array pointer is preserved.
Updated by Marc Bastian Heinrichs about 2 years ago
- Status changed from New to Needs Feedback
Hey Claus, I couldn't find your change in gerrit. Did you pushed it?
Updated by Mr. Hudson about 2 years ago
Patch set 1 of change I52c676b2660288d29d228044b92ada8ce6e3581b has been pushed to the review server.
It is available at http://review.typo3.org/2148
Updated by Claus Due about 2 years ago
I think I reset my git repository by mistake, still getting used to git instead of SVN - re-uploaded now as 8f66be7.
Updated by Sebastian Kurfuerst about 2 years ago
- Has patch set to No
Hey Claus,
could you please provide a use case and/or a test for this? I don't see yet which problem this solves.
Greets,
Sebastian
Updated by Stefan Neufeind about 2 years ago
Use case: It should be possible to call toArray() without changing the current array-position (the cursor).
Try the following with and without the array_values()-row.
class C {
var $storage;
public function toArray() {
$array = array();
$storage = array_values($this->storage);
foreach ($storage as $item) {
$array[] = $item['obj'];
}
return $array;
}
}
$c = new C();
$c->storage = array(1,2,3,4);
reset($c->storage);
next($c->storage);
next($c->storage);
echo 'First: '.current($c->storage)."\n";
$x = $c->toArray();
echo 'Second: '.current($c->storage)."\n";Updated by Marc Bastian Heinrichs almost 2 years ago
- Status changed from Needs Feedback to Resolved
- Assignee changed from Marc Bastian Heinrichs to Claus Due
commited in 34531eb5d74fc961cf2ca31e2064ae4629b42af2