ID: 28831 User updated by: nospam0 at malkusch dot de -Summary: ArrayObject::offsetGet() does not return a stored ArrayObject Reported By: nospam0 at malkusch dot de -Status: Bogus +Status: Open Bug Type: Arrays related Operating System: * PHP Version: 5.0.* Assigned To: helly New Comment:
> Returning "not a reference" = "creating a copy". That's > why. That's why offsetGet deletes the entry? Perhaps you didn't get what I mean and actually the subject for this bug is wrong, so I changed it (Sorry I was fixed on the 2D ArrayObject). Try: <?php $array = new ArrayObject(); $array->append('test'); var_dump($array); $array->offsetGet(0); var_dump($array); ?> It will return object(ArrayObject)#1 (1) { [0]=> string(4) "test" } object(ArrayObject)#1 (1) { [0]=> NULL } So, In my eyes it is a bug, that offsetGet deletes the entry from the ArrayObject. It should return a copy (or better a reference) and not touch the ArrayObject. Previous Comments: ------------------------------------------------------------------------ [2004-06-20 11:44:18] [EMAIL PROTECTED] Returning "not a reference" = "creating a copy". That's why. Hopefully we are able to return references in 5.1 so we can solve this then ------------------------------------------------------------------------ [2004-06-20 05:19:38] nospam0 at malkusch dot de > Try this code: > <?php > > $array = new ArrayObject(); > $subArray = new ArrayObject(); > $array->append($subArray); > > $subArray->append(\'item\'); > var_dump($array); > > $x=$array->offsetGet(0); > $x->append(\'item2\'); > var_dump($array); > var_dump($x); > > ?> I don't think, that the output is expected: object(ArrayObject)#1 (1) { [0]=> object(ArrayObject)#2 (1) { [0]=> string(4) "item" } } object(ArrayObject)#1 (1) { [0]=> NULL } object(ArrayObject)#2 (2) { [0]=> string(4) "item" [1]=> string(5) "item2" } Why is there a NULL in the second var_dump? If offsetGet() would not return a reference I would at least expect, that my ArrayObject won't loose its entry. It seems that offsetGet() does the work of offsetUnset(). ------------------------------------------------------------------------ [2004-06-18 20:55:21] [EMAIL PROTECTED] Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Unfortunatley internal functions cannot return a reference....... Try this code: <?php $array = new ArrayObject(); $subArray = new ArrayObject(); $array->append($subArray); $subArray->append(\'item\'); var_dump($array); $x=$array->offsetGet(0); $x->append(\'item2\'); var_dump($array); var_dump($x); ?> ------------------------------------------------------------------------ [2004-06-18 16:19:13] nospam0 at malkusch dot de Description: ------------ If I save an ArrayObject in an ArrayObject, I can't manipulate the stored ArrayObject, by getting it with offsetGet() Reproduce code: --------------- $array = new ArrayObject(); $subArray = new ArrayObject(); $array->append($subArray); $subArray->append('item'); var_dump($array); $array->offsetGet(0)->append('item2'); var_dump($array); Expected result: ---------------- object(ArrayObject)#23 (1) { [0]=> object(ArrayObject)#24 (1) { [0]=> string(4) "item" } } oobject(ArrayObject)#23 (1) { [0]=> object(ArrayObject)#24 (1) { [0]=> string(4) "item", [1]=> string(5) "item2" } } Actual result: -------------- object(ArrayObject)#23 (1) { [0]=> object(ArrayObject)#24 (1) { [0]=> string(4) "item" } } object(ArrayObject)#23 (1) { [0]=> NULL } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=28831&edit=1