|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73563 ArrayAccess by reference does not error if returns offsetGet by-ref
Submitted: 2016-11-18 11:52 UTC Modified: 2021-07-07 12:25 UTC
From: Assigned: cmb (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.13 OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
26 + 37 = ?
Subscribe to this entry?

 [2016-11-18 11:52 UTC]
If offsetGet() returns by-ref it should not be possible to assign to it by-ref.

It does not even emit "Notice: Indirect modification of overloaded element of ArrayAccessImpl has no effect".

It just silently does nothing.

Test script:
// essentially tests/classes/array_access_012.phpt, with offsetGet returning by-ref

class ArrayAccessImpl implements ArrayAccess {
        private $data = array();

        public function offsetUnset($index) {}

        public function offsetSet($index, $value) {
                $this->data[$index] = $value;

        public function &offsetGet($index) {
                return $this->data[$index];

        public function offsetExists($index) {
                return isset($this->data[$index]);

$data = new ArrayAccessImpl();
$test = 'some data';
$data['element'] = NULL; // prevent notice
$data['element'] = &$test;

Expected result:
Fatal error: Uncaught Error: Cannot assign by reference to overloaded object ...

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-07 12:25 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-07-07 12:25 UTC]
This is fixed as of PHP 7.3.0: <>.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Sep 26 16:03:36 2021 UTC