php.net |  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: bwoebi@php.net Assigned: cmb (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.13 OS: Irrelevant
Private report: No CVE-ID: None
 [2016-11-18 11:52 UTC] bwoebi@php.net
Description:
------------
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:
---------------
<?php
// 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;
var_dump($data['element']);

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

Actual result:
--------------
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-07 12:25 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-07-07 12:25 UTC] cmb@php.net
This is fixed as of PHP 7.3.0: <https://3v4l.org/UmZcJ>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC