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: -
From: bwoebi@php.net Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: 7.0.13 OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bwoebi@php.net
New email:
PHP Version: OS:

 

 [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

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Jul 17 12:01:25 2019 UTC