php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33645 Cannot modify arrays returned by ArrayAccess::offsetGet()
Submitted: 2005-07-11 15:18 UTC Modified: 2005-07-11 20:05 UTC
From: vma1 at abv dot bg Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.1.0b2 OS: Linux
Private report: No CVE-ID: None
 [2005-07-11 15:18 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-11 20:05 UTC] sniper@php.net
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

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 14 20:01:31 2024 UTC