|  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: -
From: Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: 7.0.13 OS: Irrelevant
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Apr 21 10:01:23 2021 UTC