[MODM-122] array_slice fails on ReferenceMany and EmbeddedMany fields Created: 17/Feb/11  Updated: 17/Feb/11  Resolved: 17/Feb/11

Status: Resolved
Project: Doctrine MongoDB ODM
Component/s: None
Affects Version/s: 1.0.0BETA1
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Vitaliy Kaplich Assignee: Jonathan H. Wage
Resolution: Invalid Votes: 0
Labels: None
Environment:

CentOS, PHP 5.3



 Description   

I am not sure if it's a bug of the framework or a bug in implementation of array_slice function in PHP
but when I try to pass @ReferenceMany field value into array_slice built-in PHP function it fails with error:

==============================================
array_slice() expects parameter 1 to be array, object given
==============================================

I know that PersistentCollection has method "slice" (at least in master branch) but my concern is backward compatibility with the code which treats ReferenceMany type fields as arrays.
The old code works perfectly until it uses array_slice.

Please let me know are there any workarounds for this or probably you guys are going to implement some fix?

Thanks a lot!



 Comments   
Comment by Jonathan H. Wage [ 17/Feb/11 ]

Hi, you need to pass an array so you can convert the iterator to an array with the iterator_to_array() method or call ->toArray() on the PersistentCollection. Then you can pass that array to array_slice()

Generated at Sun Sep 21 04:14:46 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.