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

From: Date: Fri, 18 Nov 2016 11:52:52 +0000
Subject: Bug #73563 [NEW]: ArrayAccess by reference does not error if returns offsetGet by-ref
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205450@lists.php.net to get a copy of this message
From: bwoebi Operating system: Irrelevant PHP version: 7.0.13 Package: Scripting Engine problem Bug Type: Bug Bug description:ArrayAccess by reference does not error if returns offsetGet by-ref 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 bug report at https://bugs.php.net/bug.php?id=73563&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73563&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73563&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73563&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=73563&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=73563&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=73563&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=73563&r=needscript Try newer version: https://bugs.php.net/fix.php?id=73563&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=73563&r=support Expected behavior: https://bugs.php.net/fix.php?id=73563&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=73563&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=73563&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=73563&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73563&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=73563&r=dst IIS Stability: https://bugs.php.net/fix.php?id=73563&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=73563&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=73563&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=73563&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=73563&r=mysqlcfg

« previous php.bugs (#205450) next »