#33645 [Opn->Bgs]: Cannot modify arrays returned by ArrayAccess::offsetGet()

From: Date: Mon, 11 Jul 2005 18:05:51 +0000
Subject: #33645 [Opn->Bgs]: Cannot modify arrays returned by ArrayAccess::offsetGet()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-81682@lists.php.net to get a copy of this message
ID: 33645 Updated by: sniper@php.net Reported By: vma1 at abv dot bg -Status: Open +Status: Bogus Bug Type: Class/Object related Operating System: Linux PHP Version: 5.1.0b2 New Comment: Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely to be the same. Thank you for your interest in PHP. See bug #32983 and bug #33582 Previous Comments: ------------------------------------------------------------------------ [2005-07-11 15:18:48] vma1 at abv dot bg Description: ------------ It is not possible to modify an element of an array returned by ArrayAccess::offsetGet(). Also the error message suggests that offsetGet() should return a reference but it is not possible due to the offsetGet() original declaration. Reproduce code: --------------- <? class obj_array implements ArrayAccess { private $array; public function __construct ($array) { $this->array = $array; } public function offsetExists ($index) { return (array_key_exists ($index, $this->array)); } public function offsetGet ($index) { return ($this->array [$index]); } public function offsetSet ($index, $value) { $this->array [$index] = $value; } public function offsetUnset ($index) { unset ($this->array [$index]); } } $obj = new obj_array (array ("index_1" => array ("index_2" => 123))); $obj ["index_1"]["index_2"] = 456; ?> Expected result: ---------------- Nothing should be displayed when the code is run. Actual result: -------------- Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in /archive/try.php on line 33 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33645&edit=1

« previous php.bugs (#81682) next »