Req #51622 [Com]: ArrayObject::offsetGet should return a reference

From: Date: Thu, 18 Nov 2021 06:14:15 +0000
Subject: Req #51622 [Com]: ArrayObject::offsetGet should return a reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237836@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=51622&edit=1 ID: 51622 Comment by: jassmol07 at gmail dot com Reported by: oliver dot graetz at gmx dot de Summary: ArrayObject::offsetGet should return a reference Status: Open Type: Feature/Change Request Package: SPL related PHP Version: 5.2.13 Block user comment: N Private report: N New Comment: We Ek-Tek Vedaz came with a vision to make priorities nutrition. We understand your concern towards your health and we believe that wellness is a way of life. We are vested in staying ahead of the curve in understanding nutrient delivery mechanisms in the body and making world-class supplements accessible and affordable to every individual around the world <a href=https://ektekvedaz.com/product/ashwagandha-veg-capsules/>ashwagandha-veg-capsules</a> Previous Comments: ------------------------------------------------------------------------ [2021-11-18 06:14:14] jassmol07 at gmail dot com We Ek-Tek Vedaz came with a vision to make priorities nutrition. We understand your concern towards your health and we believe that wellness is a way of life. We are vested in staying ahead of the curve in understanding nutrient delivery mechanisms in the body and making world-class supplements accessible and affordable to every individual around the world <a href=https://ektekvedaz.com/product/ashwagandha-veg-capsules/>ashwagandha-veg-capsules</a> ------------------------------------------------------------------------ [2021-11-18 06:10:31] kauramanat238 at gmail dot com We All4pets came with a vision to make pet parenting hassle free. Getting a pet is like getting a child they need our care concern and also all the basic needs <a href="https://www.all4pets.in/products/pet-accessories/dog-cages/">dog cage</a> ------------------------------------------------------------------------ [2013-04-16 04:54:33] me at achronos dot ca Although no php dev has ever mentioned it in a bug report (that I can find), this issue has in fact been fixed. At least, it has been fixed for ArrayAccess. For ArrayObject, I haven't tested. According to the PHP docs (http://php.net/manual/en/arrayaccess.offsetget.php notes section) this was fixed in 5.3.4 by relaxing the requirements for implementing AccessAccess, so that public function &offsetGet($offset) {} works, and thus indirect access works. I've confirmed this does in fact work (on 5.3.8). There are multiple bug reports all related to this topic: https://bugs.php.net/bug.php?id=51622 https://bugs.php.net/bug.php?id=34783 https://bugs.php.net/bug.php?id=32983 ------------------------------------------------------------------------ [2011-02-18 23:35:18] urkle at outoforder dot cc Is this issue fixed in PHP 5.3.4 which supports defining &offsetGet ? (As documented in http://php.net/manual/en/arrayaccess.offsetget.php ) Actually Just tested and it's not.. Though ArrayAccess by itself works wonderfully. --- Test script (Tested on PHP 5.3.5 x86_64 on Fedora 14) <?php class Test implements ArrayAccess { private $data = array(); /** Array Access */ public function offsetExists($offset) { return isset($this->data[$offset]); } public function &offsetGet($offset) { return $this->data[$offset]; } public function offsetSet($offset, $value) { $this->data[$offset] = $value; } public function offsetUnset($offset) { unset($this->data[$offset]); } } class Test2 extends ArrayObject { public function &offsetGet($offset) { $t =& parent::offsetGet($offset); return $t; } } $t = new Test(); $t['test'] = array(1,2,3,4); echo serialize($t)."\n"; $t['test'][] = 5; echo serialize($t)."\n"; $t = new Test2(); $t['test'] = array(1,2,3,4); echo serialize($t)."\n"; $t['test'][] = 5; echo serialize($t)."\n"; ------------------------------------------------------------------------ [2010-08-18 10:21:25] golgote at mamasam dot com I'd like to see a solution to this problem as well. I have spent countless hours trying to use ArrayObject and ArrayAccess and they both have problems either with get and unset. An unset() on an ArrayObject issues the notice : $object["list"][0]["prods"] = "1,3"; $object["list"][0]["cache"][1] = array( 'name' => 'p3', 'categories' => array( array('category' => 'c3'), ), 'price' => 3 ); unset($object["list"][0]["cache"][2]); will issue Notice: Indirect modification of overloaded element... while this works with ArrayAccess! But something like a straight : $object['arr'][0]['foo'] = 'bar'; will issue the notice with ArrayAccess but not with an ArrayObject! It's really silly. I suggest that since this bug hasn't been fixed since 2005, it should be documented clearly that neither ArrayAccess and ArrayObject work correctly with multidimensional arrays and are just quick, funny but useless hacks so that people stop wasting their time with them. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=51622 -- Edit this bug report at https://bugs.php.net/bug.php?id=51622&edit=1

« previous php.bugs (#237836) next »