Bug #73563 [Opn->Csd]: ArrayAccess by reference does not error if returns offsetGet by-ref

From: Date: Wed, 07 Jul 2021 12:25:34 +0000
Subject: Bug #73563 [Opn->Csd]: ArrayAccess by reference does not error if returns offsetGet by-ref
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234865@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73563&edit=1 ID: 73563 Updated by: cmb@php.net Reported by: bwoebi@php.net Summary: ArrayAccess by reference does not error if returns offsetGet by-ref -Status: Open +Status: Closed Type: Bug Package: Scripting Engine problem Operating System: Irrelevant PHP Version: 7.0.13 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: This is fixed as of PHP 7.3.0: <https://3v4l.org/UmZcJ>. Previous Comments: ------------------------------------------------------------------------ [2016-11-18 11:52:51] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73563&edit=1

« previous php.bugs (#234865) next »